Showing posts with label processed. Show all posts
Showing posts with label processed. Show all posts

Friday, March 30, 2012

How to get the Training Error from the Model?

Hi, everyone here.

I am trying to get the training error of the model processed which can reveal how much the model fits the cases. The training error can reveal how many cases (from training set) are classified correctly. The lower traing error is, the more the model fits the training set. (Maybe overfitted) But I found it hard to get. I saw the life chart in AS 2005 which I am not quite understand and don't know how to code it in my program.

Is there some way to getting traing error or predicting error?

I am now using this awful way to get the training error:

select t.*,CollegeTree.CollegePlans as pred

from collegetree
prediction join
openquery(DSource,'select * from CollegePlans') as t
on CollegeTree.StudentID = t.StudentID and
...
where t.CollegePlans = CollegeTree.CollegePlans;

and then use datareader.ItemCount to get the count of cases which classified correctly.

Keyword: train error,predict error, data mining, analysis service

Instead of the lift chart, you could use the classification matrix (it is next to the lift chart in BI dev studio).

The Classification Matrix gives you the exactly the number of correct vs. incorrect classifications

|||Thx, it is what I need. I am still wondering how to program with the classification matrix. Can I just get it from SQL statement or AMO? And that classification matrix need a prediction procedure that may take too long time. Could I get the training error just after the model trained?|||Currently, there is no way to get the training error just after the model trained.
The Classification Matrix is a stored procedure call. The syntax is a bit complex (an XML encoding of the queries used to compute the matrix) and the easiest way to get the statement is to
- launch SQL Server Profiler
- Connect to the Analysis Services server
- Launch the classification matrix in the tools
- look in the profiler for a statement beginning with CALL Microsoft.AnalysisServices.System.DataMining.GetConfusionMatricesUsingDatasource

Then, you can execute that statement as any other DMX statement|||

Thx for your advice, it's really helpful.

I'm now using

Code Snippet

select flattened topcount((select [SUPPORT] from NODE_DISTRIBUTION),[SUPPORT],1) from DModel.content where NODE_TYPE=4

to export the number of positive cases for every rule, i.e. the max [support] for the leaf node( NODE_TYPE=4),

and add them up.

Code Snippet

While DSReader.Read()
pCase = pCase + DSReader(0)
End While
DMTrainingError = pCase/TotalCasesCount

I hava checked the result with the BI Classification Matrix, which prooved my idea.

The rules after processing the model are stored in a table named <Model Name>.content, and the column of NODE_DISTRIBUTION is a nested table containing the cases distribution of each class, and the prediction follows the most probable class with the max support.

So pick up the max value of support in every NODE_DISTRIBUTION and add them up, then you will get the number of positive cases. The ratio of positive cases in all cases can be used as Training Error.

How to get the Training Error from the Model?

Hi, everyone here.

I am trying to get the training error of the model processed which can reveal how much the model fits the cases. The training error can reveal how many cases (from training set) are classified correctly. The lower traing error is, the more the model fits the training set. (Maybe overfitted) But I found it hard to get. I saw the life chart in AS 2005 which I am not quite understand and don't know how to code it in my program.

Is there some way to getting traing error or predicting error?

I am now using this awful way to get the training error:

select t.*,CollegeTree.CollegePlans as pred

from collegetree
prediction join
openquery(DSource,'select * from CollegePlans') as t
on CollegeTree.StudentID = t.StudentID and
...
where t.CollegePlans = CollegeTree.CollegePlans;

and then use datareader.ItemCount to get the count of cases which classified correctly.

Keyword: train error,predict error, data mining, analysis service

Instead of the lift chart, you could use the classification matrix (it is next to the lift chart in BI dev studio).

The Classification Matrix gives you the exactly the number of correct vs. incorrect classifications

|||Thx, it is what I need. I am still wondering how to program with the classification matrix. Can I just get it from SQL statement or AMO? And that classification matrix need a prediction procedure that may take too long time. Could I get the training error just after the model trained?|||Currently, there is no way to get the training error just after the model trained.
The Classification Matrix is a stored procedure call. The syntax is a bit complex (an XML encoding of the queries used to compute the matrix) and the easiest way to get the statement is to
- launch SQL Server Profiler
- Connect to the Analysis Services server
- Launch the classification matrix in the tools
- look in the profiler for a statement beginning with CALL Microsoft.AnalysisServices.System.DataMining.GetConfusionMatricesUsingDatasource

Then, you can execute that statement as any other DMX statement|||

Thx for your advice, it's really helpful.

I'm now using

Code Snippet

select flattened topcount((select [SUPPORT] from NODE_DISTRIBUTION),[SUPPORT],1) from DModel.content where NODE_TYPE=4

to export the number of positive cases for every rule, i.e. the max [support] for the leaf node( NODE_TYPE=4),

and add them up.

Code Snippet

While DSReader.Read()
pCase = pCase + DSReader(0)
End While
DMTrainingError = pCase/TotalCasesCount

I hava checked the result with the BI Classification Matrix, which prooved my idea.

The rules after processing the model are stored in a table named <Model Name>.content, and the column of NODE_DISTRIBUTION is a nested table containing the cases distribution of each class, and the prediction follows the most probable class with the max support.

So pick up the max value of support in every NODE_DISTRIBUTION and add them up, then you will get the number of positive cases. The ratio of positive cases in all cases can be used as Training Error.

sql

Friday, February 24, 2012

How to get last processed date of stored procedure

Hello everybody
Help me to get the last processed date of a stored procedure.The last time it was invoked, or the last time the code was altered?|||... and to short cut a bit.

Invocation cannot be established after the event - you would need to log the execution somewhere or be running a trace.
Alteration only shows up in SS 2005 - SS 2000 only has a creation date so if you altered rather than drop\ created you are out of luck.|||The last time it was invoked, or the last time the code was altered?

i just want the date on which the stored procedure was executed and where the lastexcuted date and other details are stored?|||i just want the date on which the stored procedure was executed and where the lastexcuted date and other details are stored?

one more doubt plz

1) the date on which the stored procedure was excuted last time
2)i want to know whether the stored procedure was excuted successfully or end with failure|||As Pootle Flump mentioned, you will have to add that audit trail detail to the code of your stored procedure. SQL Server (nor any other RDBMS that I know of) will keep this sort of information.|||I create my own logging for all stroed procedures...comes in very handy

Just call this...get the datetime on the way in, and the last datetime on the way out

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_LogProcCalls]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[usp_LogProcCalls]
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[usp_LogProcCalls] (
@.SprocName sysname
, @.TranStart datetime
, @.TranEnd datetime
, @.APPUSER char(30)
, @.Rows int
, @.Err int
, @.Paramters varchar(255)
, @.rc int OUTPUT)
AS
SET NOCOUNT ON
--
-- Enterprise Solutions
--
-- File: \\paerscbvd0014\Succession\Procedures
-- Date: 01/04/2006
-- Author: Brett Kaiser
-- Server: paerscbvd0014
-- Database: Succession
-- Login: sa
-- Description: This Procedure will log all procedures executed in a database
--
--
-- The stream will do the following:
--
-- '1. Function...

--
-- Tables Used: Sproc_Log
--
-- Tables Created: None
--
--
-- Row Estimates:
-- name rows reserved data index_size unused
-- ------------------------------
-- Sproc_Log 0 0 KB 0 KB 0 KB 0 KB
--
-- sp_spaceused Sproc_Log

--Change Log
--
-- UserId Date Description
-- ---- ----- ---------------------------
-- x002548 01/01/2006 1. Initial release
--
--
--

Declare @.error int, @.RowCount int, @.Error_Message varchar(255), @.Error_Type int, @.Error_Loc int

BEGIN TRAN
DECLARE @.LogStart datetime
SELECT @.rc = 0, @.LogStart = GetDate()
IF (SELECT @.@.TRANCOUNT) <> 1
BEGIN
SELECT @.Error_Loc = 1
, @.Error_Message = 'The logging procedure must be executed outside of any transaction. @.@.TRANSCOUNT='
+ CONVERT(varchar(5),@.@.TRANCOUNT)
, @.Error_Type = 50002, @.rc = -6661
GOTO usp_LogProcCalls_Error
END

INSERT INTO Sproc_Log (
[SprocName]
, [TranStart]
, [TranEnd]
, [APP_USER]
, [LogStart]
, [LogEnd]
, [Rows]
, [Err]
, [Paramters])
SELECT
@.SprocName
, @.TranStart
, @.TranEnd
, @.APPUSER
, @.LogStart
, GetDate()
, @.Rows
, @.Err
, @.Paramters

Select @.RowCount = @.@.ROWCOUNT, @.error = @.@.error

IF @.error <> 0
BEGIN
SELECT @.Error_Loc = 2, @.Error_Type = 50001, @.rc = -6662
GOTO usp_LogProcCalls_Error
END

IF @.RowCount <> 1
BEGIN
SELECT @.Error_Loc = 3
, @.Error_Message = 'Expected 1 row to be inserted in to the sproc log. Actual Number inserted = '
+ CONVERT(varchar(5),@.RowCount)
, @.Error_Type = 50002, @.rc = -6663
GOTO usp_LogProcCalls_Error
END

COMMIT TRAN

usp_LogProcCalls_Exit:

-- Place any house keeping procedures here like...

--Set ansi_warnings ON
SET NOCOUNT OFF

RETURN

usp_LogProcCalls_Error:

Rollback TRAN

If @.Error_Type = 50001
BEGIN

Select @.error_message = (Select 'Location: ' + ',"' + RTrim(Convert(char(3),@.Error_Loc))
+ ',"' + ' @.@.ERROR: ' + ',"' + RTrim(Convert(char(6),error))
+ ',"' + ' Severity: ' + ',"' + RTrim(Convert(char(3),severity))
-- + ',"' + ' Message: ' + ',"' + RTrim(description)
From master..sysmessages
Where error = @.error)
END

If @.Error_Type = 50002

BEGIN
Select @.Error_Message = 'Location: ' + ',"' + RTrim(Convert(char(3),@.Error_Loc))
+ ',"' + ' Severity: UserLevel '
+ ',"' + ' Message: ' + ',"' + RTrim(@.Error_Message)
END

RAISERROR @.Error_Type @.Error_Message

GOTO usp_LogProcCalls_Exit

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

how to get last processed date of a stored procedure

Hello

help me to get last processed date of a stored procedure in sql server 2005

Quote:

Originally Posted by sukumaster

Hello

help me to get last processed date of a stored procedure in sql server 2005


One More doubt

1) the date on which the stored procedure was excuted last time
2)i want to know whether the stored procedure was excuted successfully or end with failure