Showing posts with label dataset. Show all posts
Showing posts with label dataset. Show all posts

Friday, March 30, 2012

Prediction with many attribute states

I have a large dataset of around 3 million records with accounting data for 2 years. Attributes are transaction amount (cont. / predict), account, cost centre, project, month and a few others. I want to predict any future transaction amount for a certain combination. For example; what will the next salary cost transaction amount in cost centre 123 probably be?

I have tried Decision trees and Neural nets. But the predictions are not good enough even if there should be clear patterns in normal accounting data.

I guess the problem is that many of the input attributes have many states. There are around 500 account, and 1000 cost centres, and 2000 projects etc. And the Decision tree doesn’t seem to be able to capture all the business rules in the company. I have tried to group the attribute states into groups based on their average amount, their parent account etc, but it doesn’t seem to solve the problem.

Please post any suggestion you might have how to improve the prediction. I will try them all and post back my findings!

/Erik

You may need to structure your model so that it creates independent models for all scenarios. Also if things like "Project" only have a few rows/state, there's likely not alot to learn from them.

To create independent models you need to move one of your attributes to a nested table. For example, if you thought that "accounts" were the most important you would create a model like this

CREATE MINING MODEL CostByAccount
{
Transaction LONG KEY,
AccountAmount TABLE
{
Account TEXT KEY,
Amount FLOAT CONTINUOUS PREDICT_ONLY
}
CostCenter LONG DISCRETE,
Project LONG DISCRETE,
Month TEXT DISCRETE,
...
} USING Microsoft_Decision_Trees(params)

This will create a different tree for each account based on input only for that account. To create this table in the UI, you will mark the source table as case and nested tables and then add Account as Key of the nested table.

|||

Thanx Jamie,

Seems like a good idea. Creating a forrest instead of a tree. The result looks as expected when browsing the created tree structres in the model viewer.

1. But is this kind of model supported by the accurancy chart? Can't seem to get it working. I add the case table, and the nested table (same table twice). But the drop-down "Predictabel column name" is empty.

2. How to write the predict query? Have used the query builder but it dosn't seem to work.

/Erik

|||

Actually, no, it doesn't work with the accuracy chart, so you would have to create your own accuracy test queries.

For predict, you should be able to do Predict(<Nested Table Name>,3) for example to get the 3 most likely categories. There are also additional tricks you can play, for example to get statistics you can do

Predict(<Nested Table Name>,INCLUDE_STATISTICS)

This will return all possible states with descriptive stats for each state. Since these functions return tables you can select from them, e.g.

SELECT (SELECT * FROM Predict(<Nested Table>, INCLUDE_STATISTICS) WHERE $Probability >0.25) as Result FROM MyModel ...

Will return all states with a 25% probability or higher.

|||

Can't follow you,

This is approx. what I would like to do. But it dosnt work. (A simplified version of the real model).

/Erik

SELECT
t.[TransactionID],
t.[Account],
t.[CostCentre],
t.[Project],
(t.[Amount]) as [ActualAmount],
(SELECT ([Amount]) as [EstimatedAmount] FROM [DesTree].[Transactions])
From
[DesTree]
PREDICTION JOIN
SHAPE {
OPENQUERY([Adb2],
'SELECT DISTINCT
[TransactionID],
[Account],
[CostCentre],
[Project],
[Amount]
FROM
[dbo].[Transactions]
ORDER BY
[TransactionID]')}
APPEND
({OPENQUERY([Adb2],
'SELECT
[Account],
[Amount],
[TransactionID]
FROM
[dbo].[Transactions]
ORDER BY
[TransactionID]')}
RELATE
[TransactionID] TO [TransactionID])
AS
[Transactions] AS t
ON
[DesTree].[Cost Centre] = t.[CostCentre] AND
[DesTree].[Project] = t.[Project] AND
[DesTree].[Transactions].[Account] = t.[Transactions].[Account] AND
[DesTree].[Transactions].[Amount] = t.[Transactions].[Amount]

|||

I think you want to do your nested select like this

SELECT FLATTENED

t.[TransactionID],
t.[Account],
t.[CostCentre],
t.[Project],
(t.[Amount]) as [ActualAmount],

(SELECT Account, Amount FROM Predict(Transactions) WHERE Account='MyAccount') as Prediction

FROM ...

The only problem here is that you can't compare the nested account to your input - only to a static string or parameter. E.g you can do WHERE Account=@.Account, but you can't do WHERE Account=t.Account.

Monday, March 12, 2012

Possible todo some form of DISTINCT filtering?

Hi guys, I have a dataset that returns rows that look like the following
field | value
--
1 | 7
1 | 7
2 | 4
8 | 90
Is it possible to remove the duplicate (1 | 7) row directly within a LIST
control (or similar?)? I cannot use a DISTINCT directly in the SQL as
elsewhere I need to display the duplicate row.
Thanks for any help
TazSilly me, thats what grouping is for lol.
Thanks anyways
Taz

Friday, March 9, 2012

Possible to reuse the same SQL dataset in many reports?

Is it possible to create a SQL query and hook this up to more than one
report? I have several reports that are supposed to be standardized to be
deployed to different clients. We want to brand the reports with each
client's name. We can get the name from the SQL Server database that the
reports are using.
Is it possible to just create this dataset "somewhere" in my report project,
and have all reports get the data returned from this dataset? Or do I have
to add this dataset to all my reports?
Sincerely,
Kaisa M. Lindahlyou can do this by using a stored procedure
"Kaisa M. Lindahl" wrote:
> Is it possible to create a SQL query and hook this up to more than one
> report? I have several reports that are supposed to be standardized to be
> deployed to different clients. We want to brand the reports with each
> client's name. We can get the name from the SQL Server database that the
> reports are using.
> Is it possible to just create this dataset "somewhere" in my report project,
> and have all reports get the data returned from this dataset? Or do I have
> to add this dataset to all my reports?
> Sincerely,
> Kaisa M. Lindahl
>
>|||I found that the best way is to put all or most of your query into a stored
procedure or in-line table function on the server so it is easily accessible
from other reports.
"Kaisa M. Lindahl" wrote:
> Is it possible to create a SQL query and hook this up to more than one
> report? I have several reports that are supposed to be standardized to be
> deployed to different clients. We want to brand the reports with each
> client's name. We can get the name from the SQL Server database that the
> reports are using.
> Is it possible to just create this dataset "somewhere" in my report project,
> and have all reports get the data returned from this dataset? Or do I have
> to add this dataset to all my reports?
> Sincerely,
> Kaisa M. Lindahl
>
>|||DavidK or Antoon or someone else:
Can you please explain how to do it? I've looked at articles on the internet
and the "Hitchhiker's" book, and I can't figure out how to use Stored
Procedures properly.
I've managed to create a stored procedure. Unfortunately, this has to be a
sp with dynamic sql. It takes 2 parameters. When I'm testing it, it works
OK, but it doesn't return any fields. So none of the results show up in the
report at all.
Any clues, please? A short explanation or links to resources on the web is
OK. :)
Sincerely,
Kaisa
"DavidK" <DavidK@.discussions.microsoft.com> wrote in message
news:649C3B02-DA26-42EA-8F4E-FD3EB1D15361@.microsoft.com...
>I found that the best way is to put all or most of your query into a stored
> procedure or in-line table function on the server so it is easily
> accessible
> from other reports.
> "Kaisa M. Lindahl" wrote:
>> Is it possible to create a SQL query and hook this up to more than one
>> report? I have several reports that are supposed to be standardized to be
>> deployed to different clients. We want to brand the reports with each
>> client's name. We can get the name from the SQL Server database that the
>> reports are using.
>> Is it possible to just create this dataset "somewhere" in my report
>> project,
>> and have all reports get the data returned from this dataset? Or do I
>> have
>> to add this dataset to all my reports?
>> Sincerely,
>> Kaisa M. Lindahl
>>|||Although u create a Stored Procedure , u need to have a dataset in all
your reports which point to the stored procedure.
In short for every report there shall be a dataset|||"Vishu" <vishwasaj@.gmail.com> wrote in message
news:1121329763.408325.84730@.g43g2000cwa.googlegroups.com...
> Although u create a Stored Procedure , u need to have a dataset in all
> your reports which point to the stored procedure.
> In short for every report there shall be a dataset
Thanks. :)
I recreated the Stored Procedure without parameters. The SP needs to be
added manually to each database anyway, so I will change it to fit with the
database in the stored procedure, not have each report send the parameters.
Adding just one line of code as a dataset + adding a text box to the report
was a lot easier than expected.
In the end I wrote a blog post about it:
http://blogs.spipp.net/kaisa/archive/2005/07/12/1154.aspx
Kaisa M. Lindahl

Possible to Loop thru dataset using Custom Code?

Is there a way to pass a record set into a function of custom code?
If so?
What datatype should I use?
I have been told its impossible to loop thru the dataset...
Can you get the INDEX of the First row and the INDEX of the last row as
a parameter into a custom function?
regards,
Stas K.Mr. Sorcerdon,
Your best bet would be to implement a Custom Data Processing extension.
This will give you access to dataset being consumed by the report.
Specifically, the IDataReader has a Read method which walks the
dataset.
Andy Potter|||I dont you to go too deep into it, but basically make an Object as a
parameter and then read that object using this extension?
Is there a place where I can get code for this Custom Data Proccessing
extension?|||It is a class library that sits between your data source and your
report's dataset. It implements interfaces from MSRS.
Here's the MSDN article about a Custom Data Processing Extension.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/rsprog/htm/rsp_prog_extend_dataproc_5c2q.asp
There are several good samples out there. Teo Lachev has a good one
that a google search will return.
Andy Potter

Wednesday, March 7, 2012

Possible to cache a dataset when testing in Visual Studio?

I do a lot of work with a report that calls a stored procedure that takes
about 2 minutes to complete. It annoys me that when I change one little
formatting property in the layout, I have to wait for the stored procedure to
run again before I can see the results of my modification. I wish that I
could just cache the dataset created by this stored procedure when I'm
testing in Visual Studio and avoid rerunning it each time I change the
formatting. Can anyone tell me if this is possible? Thanks.It sounds like you did not install SP1 on your report designer machine. See
this section of the SP1 readme:
http://download.microsoft.com/download/7/f/b/7fb1a251-13ad-404c-a034-10d79ddaa510/SP1Readme_EN.htm#_report_designer_preview
SP1 can be downloaded here:
http://www.microsoft.com/downloads/details.aspx?FamilyId=580FEBF7-2972-40E7-BCCF-6CD90AC2F464&displaylang=en
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"Stefan Wrobel" <StefanWrobel@.discussions.microsoft.com> wrote in message
news:FD067DE7-1DD1-463F-90E1-F835206D966C@.microsoft.com...
>I do a lot of work with a report that calls a stored procedure that takes
> about 2 minutes to complete. It annoys me that when I change one little
> formatting property in the layout, I have to wait for the stored procedure
> to
> run again before I can see the results of my modification. I wish that I
> could just cache the dataset created by this stored procedure when I'm
> testing in Visual Studio and avoid rerunning it each time I change the
> formatting. Can anyone tell me if this is possible? Thanks.