ISmRandomForest.ROCcurve

Syntax

ROCcurve: IROCcurve;

Description

The ROCcurve property returns ROC curve parameters.

Comments

A ROC curve is a graph that enables the user to assess the quality of binary classification. A ROC curve displays relation between the share of objects from the total number of attribute bearers that are correctly identifier as attribute bearers, and the share of objects from the total number of objects that are not attribute bearers and that are by error identifier as attribute bearers on varying of decision rule threshold.

Thus, a ROC curve is calculated if an explanatory series is binary.

A ROC curve is plotted by laying off the obtained sensitivity values along the Y axis, and (1 - specificity) along the X axis.

Example

To execute the example, add a link to the Stat system assembly.

Sub UserProc;
Var
    RF: SmRandomForest;
    ROCCurve: IROCcurve;
    y: Array[
16Of Integer;
    x3dbl: array[
16Of Double;
    i, res: Integer;
    OneMinusSpecificity, Sensitivity: Array 
Of Double;
Begin
    
// Create a method
    RF := New SmRandomForest.Create;
    
// Set initial data
    // Set values corresponding to  age group
    y[0] := 5; y[1] := 5; y[2] := 5; y[3] := 5;
    y[
4] := 5; y[5] := 5; y[6] := 5; y[7] := 5;
    y[
8] := 1; y[9] := 1; y[10] := 1; y[11] := 1;
    y[
12] := 1; y[13] := 1; y[14] := 1; y[15] := 1;
    
// Set values of explanatory quantitative series    
    x3dbl[0] := 1.1; x3dbl[1] := 2.1;   x3dbl[2] := 3;  x3dbl[3] := 5;
    x3dbl[
4] := 40; x3dbl[5] := 6; x3dbl[6] := 7; x3dbl[7] := 8;
    x3dbl[
8] := 9; x3dbl[9] := 9; x3dbl[10] := 10; x3dbl[11] := 10;
    x3dbl[
12] := 11; x3dbl[13] := 12; x3dbl[14] := 13; x3dbl[15] := 1.4;
    
// Determine method parameters
    RF.ForestSize := 20;
    RF.NumberOfPredictors := 
2;
    RF.LearningSamplePortion := 
0.67;
    
// Determine tree size
    RF.TreeSizeSpecification.MaximumNumberOfLevels := 10;
    RF.TreeSizeSpecification.MinimumNumberOfCases := 
2
    
// Set explained series
    RF.Dependent.Value := y;
    
// Set explanatory sequence series
    RF.ExplanatoriesContinuous.Add.Value := x3dbl;
    
// Execute calculation and display values to the console window
    res := RF.Execute;
    ROCCurve := RF.ROCcurve;
    Debug.WriteLine(RF.Errors);
    Debug.WriteLine(RF.Forest.Count.ToString);
    
If res <> 0 Then
        Debug.WriteLine(
"Failed");
    
Else
        
If ROCCurve <> Null Then
            Debug.WriteLine(
"ROC curve data:");
            Debug.Indent;
            Debug.WriteLine(
"Specifity:");
            Debug.Indent;
            OneMinusSpecificity := ROCcurve.OneMinusSpecificity;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008080">For</font><font color="#000000">&nbsp;i&nbsp;:=&nbsp;</font><font color="#008000">0</font><font color="#000000">&nbsp;</font><font color="#008080">To</font><font color="#000000">&nbsp;OneMinusSpecificity.Length&nbsp;-&nbsp;</font><font color="#008000">1</font><font color="#000000">&nbsp;</font><font color="#008080">Do</font><font color="#000000"><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(OneMinusSpecificity[i]);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008080">End</font><font color="#000000">&nbsp;</font><font color="#008080">For</font><font color="#000000">;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.Unindent;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(</font><font color="#800000">&quot;Sensitivity:&quot;</font><font color="#000000">);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.Indent;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sensitivity&nbsp;:=&nbsp;ROCcurve.Sensitivity;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008080">For</font><font color="#000000">&nbsp;i&nbsp;:=&nbsp;</font><font color="#008000">0</font><font color="#000000">&nbsp;</font><font color="#008080">To</font><font color="#000000">&nbsp;Sensitivity.Length&nbsp;-&nbsp;</font><font color="#008000">1</font><font color="#000000">&nbsp;</font><font color="#008080">Do</font><font color="#000000"><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(Sensitivity[i]);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008080">End</font><font color="#000000">&nbsp;</font><font color="#008080">For</font><font color="#000000">;<br/> &nbsp;</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font><font color="#000000">&nbsp;</font><font color="#008080">If</font><font color="#000000">;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Display&nbsp;classification&nbsp;quality&nbsp;criteria<br/> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.Unindent;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.Unindent;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(</font><font color="#800000">&quot;Classification&nbsp;quality&nbsp;criteria&quot;</font><font color="#000000">);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(</font><font color="#800000">&quot;Overall&nbsp;accuracy:&nbsp;&quot;</font><font color="#000000">&nbsp;+&nbsp;RF.RelevanceMeasure.Accuracy.ToString);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(</font><font color="#800000">&quot;F&nbsp;-&nbsp;estimate:&nbsp;&quot;</font><font color="#000000">&nbsp;+&nbsp;RF.RelevanceMeasure.F1.ToString);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(</font><font color="#800000">&quot;Number&nbsp;of truly positive&nbsp;values:&nbsp;&quot;</font><font color="#000000">&nbsp;+&nbsp;RF.RelevanceMeasure.TruePositive.ToString);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(</font><font color="#800000">&quot;Number&nbsp;of truly negative&nbsp;values:&nbsp;&quot;</font><font color="#000000">&nbsp;+&nbsp;RF.RelevanceMeasure.TrueNegative.ToString);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(</font><font color="#800000">&quot;Number&nbsp;of false positive&nbsp;values:&nbsp;&quot;</font><font color="#000000">&nbsp;+&nbsp;RF.RelevanceMeasure.FalsePositive.ToString);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(</font><font color="#800000">&quot;Number&nbsp;of false negative&nbsp;values:&nbsp;&quot;</font><font color="#000000">&nbsp;+&nbsp;RF.RelevanceMeasure.FalseNegative.ToString);<br/> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008080">End</font><font color="#000000">&nbsp;</font><font color="#008080">If</font><font color="#000000">;<br/> </font><font color="#008080">End</font><font color="#000000">&nbsp;</font><font color="#008080">Sub</font><font color="#000000">&nbsp;UserProc;</font>

After executing the example, the console window will display ROC curve data and classification quality criteria.

See also:

ISmRandomForest