IDmLogisticRegression.Threshold

Fore Syntax

Threshold: Double;

Fore.NET Syntax

Threshold: double;

Description

The Threshold property determines a threshold value.

Comments

Range of available values: (0;1].

Fore Example

Executing the example requires that the repository contains a table containing data for analysis with the DM_TABLE identifier. A regular report with the DM_REPORT_RES identifier where analysis results will be loaded must also be present.

Add links to the Metabase, Ms, Report, Stat, Tab system assemblies.

Sub UserProc;
Var
    mb: IMetabase;
    ReportDS: IDmReportDataSource;
    TableDS: IDmTableDataSource;
    Method: IDmMethod;
    Report: IPrxReport;
    Shs: IPrxSheets;
    Sheet: ITabSheet;
    DM: IDmLogisticRegression;
    i, j: Integer;
    Attrs: Array Of Integer;
    CrossValidation: IDmMethodCrossValidation;
    Reports: IDmReports;
    DmReport: IDmReport;
    CrossValPerf: ICrossValidationPerformanceScores;
    CategoriesList: Array Of Integer;
    PerformanceMatrix: Array Of Double;
Begin
    mb := MetabaseClass.Active;
    // Create calculation method
    Method := (New DataMiningMethod.Create) As IDmMethod;
    // Specify method type
    Method.Kind := DmMethodKind.LogisticRegression;
    // Create table data source
    TableDS := (New TableDataSource.Create) As IDmTableDataSource;
    // Determine source table
    TableDS.Table := mb.ItemByID("DM_TABLE").Bind;
    // Set input data source
    Method.InputDataSource := TableDS;
    // Create a data source that is a regular report
    ReportDS := (New ReportDataSource.Create) As IDmReportDataSource;
    // Set data consumer
    Method.OutputDataSource := ReportDS;
    // Set up calculation method parameters
    DM := Method.Details As IDmLogisticRegression;
    // Set factors impacting analyzed attribute
    Attrs := New Integer[TableDS.FieldCount - 1];
    For i := 0 To Attrs.Length - 1 Do
        Attrs[i] := i + 1;
    End For;
    DM.Attributes := Attrs;
    // Specify analyzed object
    DM.Target := ReportDS.FieldCount;
    // Set threshold
    DM.Threshold := 0.57;
    // Set up cross-validation parameters
    CrossValidation := DM.CrossValidation;
    // Specify that cross-validation is used
    CrossValidation.Active := True;
    // Set cross-validation method: Repeated random sub-sampling cross-validation
    CrossValidation.SamplingType := CrossValidationSamplingType.RandomSampling;
    // Set number of repetitions
    CrossValidation.NumberOfRandomTests := 15;
    // Set training set size
    CrossValidation.TrainingSetSize := 75;
    // Perform analysis and output results
    Reports := Method.Execute;
    DmReport := reports.FindByType(DmReportType.LogisticRegression);
    ReportDS := DmReport.Generate;
    ReportDS.TabSheet.View.Selection.SelectAll;
    ReportDS.TabSheet.View.Selection.Copy;
    // Get regular report to which results will be unloaded
    Report := mb.ItemByID("DM_REPORT_RES").Edit As IPrxReport;
    Shs := Report.Sheets;
    Shs.Clear;
    Sheet := (Shs.Add("", PrxSheetType.Table) As IPrxTable).TabSheet;
    Sheet.Table.Paste;
    Sheet.Columns(01).AdjustWidth;
    Sheet.Rows(01).AdjustHeight;
    Report.Sheets.Item(0).Name := ReportDS.Caption;
    // Save unloaded data
    (Report As IMetabaseObject).Save;
    // Display cross-validation results
    DmReport := reports.FindByType(DmReportType.CrossValidation);
    DmReport.Generate;
    CrossValPerf := CrossValidation.Results;
    Debug.WriteLine("Cross-validation results:");
    Debug.Indent;
    Debug.WriteLine("Analyzed attribute: " + CrossValPerf.ClassificatorName);
    Debug.Write("Number of factors influencing the analyzed attribute: ");
    Debug.WriteLine(CrossValPerf.FactorsNumber);
    Debug.WriteLine("Number of observations: " + CrossValPerf.ObservationsNumber.ToString);
    Debug.WriteLine("Number of repetitions: " + CrossValidation.NumberOfRandomTests.ToString);
    Debug.WriteLine("Accuracy of classification: " + CrossValPerf.ClassificationAccuracy.ToString);
    Debug.WriteLine("Categories:");
    Debug.Indent;
    CategoriesList := CrossValPerf.CategoriesList;
    For i := 0 To CategoriesList.Length - 1 Do
        Debug.WriteLine(CategoriesList[i]);
    End For;
    Debug.Unindent;
    Debug.WriteLine("Correct classification:");
    Debug.Indent;
    PerformanceMatrix := CrossValPerf.PerformanceMatrix;
    For i := 0 To PerformanceMatrix.GetUpperBound(1Do
        For j := 0 To PerformanceMatrix.GetUpperBound(2Do
            Debug.Write(PerformanceMatrix[i, j].ToString + #9);
        End For;
    Debug.WriteLine("");
    End For;
    Debug.Unindent;
    Debug.Unindent;
End Sub UserProc;

After executing the example missing data is substituted for the DM_TABLE table by means of logistic regression, analysis results are unloaded to the DM_REPORT_RES report, cross-validation results are displayed in the console window.

Fore.NET Example

The requirements and result of the Fore.NET example execution match with those in the Fore example.

Imports Prognoz.Platform.Interop.Ms;
Imports Prognoz.Platform.Interop.Report;
Imports Prognoz.Platform.Interop.Stat;
Imports Prognoz.Platform.Interop.Tab;

Public Shared Sub Main(Params: StartParams);
Var
    mb: IMetabase;
    ReportDS: IDmReportDataSource;
    TableDS: IDmTableDataSource;
    Method: IDmMethod;
    CrossValidation: IDmMethodCrossValidation;
    Report: IPrxReport;
    Shs: IPrxSheets;
    Sheet: ITabSheet;
    DM: IDmLogisticRegression;
    i, j: Integer;
    Attrs: Array Of Integer;
    Reports: IDmReports;
    DmReport: IDmReport;
    CrossValPerf: ICrossValidationPerformanceScores;
    CategoriesList, PerformanceMatrix: System.Array;
Begin
    mb := Params.Metabase;
    // Create calculation method
    Method := (New DataMiningMethod.Create()) As IDmMethod;
    // Specify method type
    Method.Kind := DmMethodKind.dmmkLogisticRegression;
    // Create table data source
    TableDS := (New TableDataSource.Create()) As IDmTableDataSource;
    // Determine source table
    TableDS.Table := mb.ItemByID["DM_TABLE"].Bind();
    // Set input data source
    Method.InputDataSource := TableDS;
    // Create a data source that is a regular report
    ReportDS := (New ReportDataSource.Create()) As IDmReportDataSource;
    // Set data consumer
    Method.OutputDataSource := ReportDS;
    // Set up calculation method parameters
    DM := Method.Details As IDmLogisticRegression;
    // Set factors impacting analyzed attribute
    Attrs := New Integer[TableDS.FieldCount - 1];
    For i := 0 To Attrs.Length - 1 Do
        Attrs[i] := i + 1;
    End For;
    DM.Attributes := Attrs;
    // Specify analyzed object
    DM.Target := ReportDS.FieldCount;
    // Set threshold
    DM.Threshold := 0.57;
    // Set up cross-validation parameters
    CrossValidation := DM.CrossValidation;
    // Specify that cross-validation is used
    CrossValidation.Active := True;
    // Set cross-validation method: Repeated random sub-sampling cross-validation
    CrossValidation.SamplingType := CrossValidationSamplingType.cvstRandomSampling;
    // Set number of repetitions
    CrossValidation.NumberOfRandomTests := 15;
    // Set training set size
    CrossValidation.TrainingSetSize := 75;
    // Perform analysis and output results
    Reports := Method.Execute();
    DmReport := reports.FindByType[DmReportType.drtLogisticRegression];
    ReportDS := DmReport.Generate();
    ReportDS.TabSheet.View.Selection.SelectAll();
    ReportDS.TabSheet.View.Selection.Copy();
    // Get regular report to which results will be unloaded
    Report := mb.ItemByID["DM_REPORT_RES"].Edit() As IPrxReport;
    Shs := Report.Sheets;
    Shs.Clear();
    Sheet := (Shs.Add("", PrxSheetType.pstTable) As IPrxTable).TabSheet;
    Sheet.Table.Paste();
    Sheet.Columns[01].AdjustWidth(-1, -1);
    Sheet.Rows[01].AdjustHeight(-1, -1);
    Report.Sheets.Item[0].Name := ReportDS.Caption;
    // Save unloaded data
    (Report As IMetabaseObject).Save();
    // Display cross-validation results
    DmReport := reports.FindByType[DmReportType.drtCrossValidation];
    DmReport.Generate();
    CrossValPerf := CrossValidation.Results;
    System.Diagnostics.Debug.WriteLine("Cross-validation results:");
    System.Diagnostics.Debug.Indent();
    System.Diagnostics.Debug.WriteLine("Analyzed attribute: " + CrossValPerf.ClassificatorName);
    System.Diagnostics.Debug.Write("Number of factors influencing the analyzed attribute: ");
    System.Diagnostics.Debug.WriteLine(CrossValPerf.FactorsNumber);
    System.Diagnostics.Debug.WriteLine("Number of observations: " + CrossValPerf.ObservationsNumber.ToString());
    System.Diagnostics.Debug.WriteLine("Number of repetitions: " + CrossValidation.NumberOfRandomTests.ToString());
    System.Diagnostics.Debug.WriteLine("Accuracy of classification: " + CrossValPerf.ClassificationAccuracy.ToString());
    System.Diagnostics.Debug.WriteLine("Categories:");
    System.Diagnostics.Debug.Indent();
    CategoriesList := CrossValPerf.CategoriesList;
    For i := 0 To CategoriesList.Length - 1 Do
        System.Diagnostics.Debug.WriteLine(CategoriesList[i]);
    End For;
    System.Diagnostics.Debug.Unindent();
    System.Diagnostics.Debug.WriteLine("Correct classification:");
    System.Diagnostics.Debug.Indent();
    PerformanceMatrix := CrossValPerf.PerformanceMatrix;
    For i := 0 To PerformanceMatrix.GetUpperBound(1Do
        For j := 0 To PerformanceMatrix.GetUpperBound(0Do
            System.Diagnostics.Debug.Write(PerformanceMatrix[j, i].ToString() + char.ConvertFromUtf32(9));
        End For;
    System.Diagnostics.Debug.WriteLine("");
    End For;
    System.Diagnostics.Debug.Unindent();
    System.Diagnostics.Debug.Unindent();
End Sub;

See also:

IDmLogisticRegression