ROCcurve: IROCcurve;
ROCcurve: Prognoz.Platform.Interop.Stat.IROCcurve;
The ROCcurve property returns ROC curve parameters.
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.
To execute the example, add a link to the Stat system assembly.
Sub UserProc;
Var
RF: SmRandomForest;
ROCCurve: IROCcurve;
y: Array[16] Of Integer;
x3dbl: array[16] Of 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;
</font><font color="#008080">For</font><font color="#000000"> i := </font><font color="#008000">0</font><font color="#000000"> </font><font color="#008080">To</font><font color="#000000"> OneMinusSpecificity.Length - </font><font color="#008000">1</font><font color="#000000"> </font><font color="#008080">Do</font><font color="#000000"><br/> Debug.WriteLine(OneMinusSpecificity[i]);<br/> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">For</font><font color="#000000">;<br/> Debug.Unindent;<br/> Debug.WriteLine(</font><font color="#800000">"Sensitivity:"</font><font color="#000000">);<br/> Debug.Indent;<br/> Sensitivity := ROCcurve.Sensitivity;<br/> </font><font color="#008080">For</font><font color="#000000"> i := </font><font color="#008000">0</font><font color="#000000"> </font><font color="#008080">To</font><font color="#000000"> Sensitivity.Length - </font><font color="#008000">1</font><font color="#000000"> </font><font color="#008080">Do</font><font color="#000000"><br/> Debug.WriteLine(Sensitivity[i]);<br/> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">For</font><font color="#000000">;<br/> </font> <font color="#008080">End</font><font color="#000000"> </font><font color="#008080">If</font><font color="#000000">;<br/> </font><font color="#008000">// Display classification quality criteria<br/> </font><font color="#000000"> Debug.Unindent;<br/> Debug.Unindent;<br/> Debug.WriteLine(</font><font color="#800000">"Classification quality criteria"</font><font color="#000000">);<br/> Debug.WriteLine(</font><font color="#800000">"Overall accuracy: "</font><font color="#000000"> + RF.RelevanceMeasure.Accuracy.ToString);<br/> Debug.WriteLine(</font><font color="#800000">"F - estimate: "</font><font color="#000000"> + RF.RelevanceMeasure.F1.ToString);<br/> Debug.WriteLine(</font><font color="#800000">"Number of truly positive values: "</font><font color="#000000"> + RF.RelevanceMeasure.TruePositive.ToString);<br/> Debug.WriteLine(</font><font color="#800000">"Number of truly negative values: "</font><font color="#000000"> + RF.RelevanceMeasure.TrueNegative.ToString);<br/> Debug.WriteLine(</font><font color="#800000">"Number of false positive values: "</font><font color="#000000"> + RF.RelevanceMeasure.FalsePositive.ToString);<br/> Debug.WriteLine(</font><font color="#800000">"Number of false negative values: "</font><font color="#000000"> + RF.RelevanceMeasure.FalseNegative.ToString);<br/> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">If</font><font color="#000000">;<br/> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">Sub</font><font color="#000000"> UserProc;</font>
Imports Prognoz.Platform.Interop.Stat;
…]
Public Shared Sub Main(Params: StartParams);
Var
RF: SmRandomForest;
ROCCurve: IROCcurve;
y: Array[16] Of integer;
x3dbl: array[16] Of double;
i, res: integer;
OneMinusSpecificity, Sensitivity: System.Array;
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;
System.Diagnostics.Debug.WriteLine(RF.Errors);
System.Diagnostics.Debug.WriteLine(RF.Forest.Count.ToString());
If res <> 0 Then
System.Diagnostics.Debug.WriteLine("Failed");
Else
If ROCCurve <> Null Then
System.Diagnostics.Debug.WriteLine("ROC curve data:");
System.Diagnostics.Debug.Indent();
System.Diagnostics.Debug.WriteLine("Specifity:");
System.Diagnostics.Debug.Indent();
OneMinusSpecificity := ROCcurve.OneMinusSpecificity;
For i := 0 To OneMinusSpecificity.Length - 1 Do
System.Diagnostics.Debug.WriteLine(OneMinusSpecificity[i]);
End For;
System.Diagnostics.Debug.Unindent();
System.Diagnostics.Debug.WriteLine("Sensitivity:");
System.Diagnostics.Debug.Indent();
Sensitivity := ROCcurve.Sensitivity;
For i := 0 To Sensitivity.Length - 1 Do
System.Diagnostics.Debug.WriteLine(Sensitivity[i]);
End For;
End If;
// Display classification quality criteria
System.Diagnostics.Debug.Unindent();
System.Diagnostics.Debug.Unindent();
System.Diagnostics.Debug.WriteLine("Classification quality criteria");
System.Diagnostics.Debug.WriteLine("Overall accuracy: " + RF.RelevanceMeasure.Accuracy.ToString());
System.Diagnostics.Debug.WriteLine("F - estimate: " + RF.RelevanceMeasure.F1.ToString());
System.Diagnostics.Debug.WriteLine("Number of truly positive values: " + RF.RelevanceMeasure.TruePositive.ToString());
System.Diagnostics.Debug.WriteLine("Number of truly negative values: " + RF.RelevanceMeasure.TrueNegative.ToString());
System.Diagnostics.Debug.WriteLine("Number of false positive values: " + RF.RelevanceMeasure.FalsePositive.ToString());
System.Diagnostics.Debug.WriteLine("Number of false negative values: " + RF.RelevanceMeasure.FalseNegative.ToString());
End If;
End Sub;
After executing the example, the console window will display ROC curve data and classification quality criteria.
See also: