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;
For i := 0 To OneMinusSpecificity.Length - 1 Do
Debug.WriteLine(OneMinusSpecificity[i]);
End For;
Debug.Unindent;
Debug.WriteLine("Sensitivity:");
Debug.Indent;
Sensitivity := ROCcurve.Sensitivity;
For i := 0 To Sensitivity.Length - 1 Do
Debug.WriteLine(Sensitivity[i]);
End For;
End If;
End If;
End Sub UserProc;
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;
End If;
End Sub;
After executing the example the console window displays calculation result.
See also: