IDmLogisticRegression.Threshold

Syntax

Threshold: Double;

Description

The Threshold property determines a threshold value.

Comments

Range of available values: (0;1].

Example

Executing the example requires that the repository contains:

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 loaded
    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 loaded 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, the missing data substitution using logistic regression will be executed for the DM_TABLE table data. Analysis results will be loaded to the DM_REPORT_RES report. Cross-validation results will be displayed in the console window.

See also:

IDmLogisticRegression