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
res, i: Integer;
CART: SmCART;
ROCcurve: IROCcurve;
y: Array[16] Of Integer;
x1: Array[16] Of Integer;
x2: Array[16] Of Integer;
x3dbl: Array[16] Of Double;
x4cat: Array[16] Of Integer;
OneMinusSpecificity, Sensitivity: Array Of Double;
Begin
// Create a method
CART := New SmCART.Create;
// Set initial data
// Set values corresponding to age group
y[0] := 1000; y[1] := 1000; y[2] := 1000; y[3] := 1000;
y[4] := 1000; y[5] := 1000; y[6] := 1000; y[7] := 1000;
y[8] := 1000; y[9] := 5002; y[10] := 5002; y[11] := 5002;
y[12] := 5002; y[13] := 5002; y[14] := 5002; y[15] := 5002;
// Set values, corresponding to social status
x1[0] := 0; x1[1] := 0; x1[2] := 0; x1[3] := 0;
x1[4] := 0; x1[5] := 0; x1[6] := 0; x1[7] := 0;
x1[8] := 0; x1[9] := 1; x1[10] := 1; x1[11] := 1;
x1[12] := 1; x1[13] := 1; x1[14] := 1; x1[15] := 1;
// Set values, corresponding to social status
x2[0] := 10; x2[1] := 10; x2[2] := 10; x2[3] := 10;
x2[4] := 10; x2[5] := 20; x2[6] := 20; x2[7] := 20;
x2[8] := 20; x2[9] := 10; x2[10] := 10; x2[11] := 20;
x2[12] := 20; x2[13] := 20; x2[14] := 20; x2[15] := 20;
// Set values of explanatory quantitative series
x3dbl[0] := 1; x3dbl[1] := 2; x3dbl[2] := 3; x3dbl[3] := 5;
x3dbl[4] := 4; 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] := 14;
// Set values of explanatory categorical series
x4cat[0] := 1; x4cat[1] := 1; x4cat[2] := 1; x4cat[3] := 1;
x4cat[4] := 1; x4cat[5] := 1; x4cat[6] := 1; x4cat[7] := 2;
x4cat[8] := 2; x4cat[9] := 2; x4cat[10] := 2; x4cat[11] := 2;
x4cat[12] := 3; x4cat[13] := 3; x4cat[14] := 3; x4cat[15] := 3;
// Determine maximum number of levels in tree
CART.TreeSizeSpecification.MaximumNumberOfLevels := 3;
// Determine minimum number of observations that can be in tree node
CART.TreeSizeSpecification.MinimumNumberOfCases := 2;
// Consider each category as an attribute
CART.TreeSizeSpecification.ReduceCategories := True;
// Set explained series
CART.Dependent.Value := y;
// Set explanatory sequence series
CART.ExplanatoriesOrdered.Add.Value := x1;
CART.ExplanatoriesOrdered. Add.Value := x2;
CART.ExplanatoriesContinuous.Add.Value := x3dbl;
CART.ExplanatoriesCategorical.Add.Value := x4cat;
// Execute calculation and display values to the console window
res := CART.Execute;
ROCcurve := CART.ROCcurve;
Debug.WriteLine(CART.Errors);
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;
// Display classification quality criteria
Debug.Unindent;
Debug.Unindent;
Debug.WriteLine(" == Qualification criteria of classification == ");
Debug.WriteLine("Overall accuracy: " + CART.RelevanceMeasure.Accuracy.ToString);
Debug.WriteLine("F - estimate: " + CART.RelevanceMeasure.F1.ToString);
Debug.WriteLine("Number of truly positive values: " + CART.RelevanceMeasure.TruePositive.ToString);
Debug.WriteLine("Number of truly negative values: " + CART.RelevanceMeasure.TrueNegative.ToString);
End If;
End Sub UserProc;
Imports Prognoz.Platform.Interop.Stat;
…
Public Shared Sub Main(Params: StartParams);
Var
res, i: integer;
CART: SmCART;
ROCcurve: IROCcurve;
y: Array[16] Of integer;
x1: Array[16] Of integer;
x2: Array[16] Of integer;
x3dbl: Array[16] Of double;
x4cat: Array[16] Of integer;
OneMinusSpecificity, Sensitivity: System.Array;
Begin
// Create a method
CART := New SmCART.Create();
// Set initial data
// Set values corresponding to age group
y[0] := 1000; y[1] := 1000; y[2] := 1000; y[3] := 1000;
y[4] := 1000; y[5] := 1000; y[6] := 1000; y[7] := 1000;
y[8] := 1000; y[9] := 5002; y[10] := 5002; y[11] := 5002;
y[12] := 5002; y[13] := 5002; y[14] := 5002; y[15] := 5002;
// Set values, corresponding to social status
x1[0] := 0; x1[1] := 0; x1[2] := 0; x1[3] := 0;
x1[4] := 0; x1[5] := 0; x1[6] := 0; x1[7] := 0;
x1[8] := 0; x1[9] := 1; x1[10] := 1; x1[11] := 1;
x1[12] := 1; x1[13] := 1; x1[14] := 1; x1[15] := 1;
// Set values, corresponding to social status
x2[0] := 10; x2[1] := 10; x2[2] := 10; x2[3] := 10;
x2[4] := 10; x2[5] := 20; x2[6] := 20; x2[7] := 20;
x2[8] := 20; x2[9] := 10; x2[10] := 10; x2[11] := 20;
x2[</font><font color="#008000">12</font><font color="#000000">] := </font><font color="#008000">20</font><font color="#000000">; x2[</font><font color="#008000">13</font><font color="#000000">] := </font><font color="#008000">20</font><font color="#000000">; x2[</font><font color="#008000">14</font><font color="#000000">] := </font><font color="#008000">20</font><font color="#000000">; x2[</font><font color="#008000">15</font><font color="#000000">] := </font><font color="#008000">20</font><font color="#000000">;<br/> </font><font color="#008000">// Set values of explanatory quantitative series<br/> </font><font color="#000000"> x3dbl[</font><font color="#008000">0</font><font color="#000000">] := </font><font color="#008000">1</font><font color="#000000">; x3dbl[</font><font color="#008000">1</font><font color="#000000">] := </font><font color="#008000">2</font><font color="#000000">; x3dbl[</font><font color="#008000">2</font><font color="#000000">] := </font><font color="#008000">3</font><font color="#000000">; x3dbl[</font><font color="#008000">3</font><font color="#000000">] := </font><font color="#008000">5</font><font color="#000000">;<br/> x3dbl[</font><font color="#008000">4</font><font color="#000000">] := </font><font color="#008000">4</font><font color="#000000">; x3dbl[</font><font color="#008000">5</font><font color="#000000">] := </font><font color="#008000">6</font><font color="#000000">; x3dbl[</font><font color="#008000">6</font><font color="#000000">] := </font><font color="#008000">7</font><font color="#000000">; x3dbl[</font><font color="#008000">7</font><font color="#000000">] := </font><font color="#008000">8</font><font color="#000000">;<br/> x3dbl[</font><font color="#008000">8</font><font color="#000000">] := </font><font color="#008000">9</font><font color="#000000">; x3dbl[</font><font color="#008000">9</font><font color="#000000">] := </font><font color="#008000">9</font><font color="#000000">; x3dbl[</font><font color="#008000">10</font><font color="#000000">] := </font><font color="#008000">10</font><font color="#000000">; x3dbl[</font><font color="#008000">11</font><font color="#000000">] := </font><font color="#008000">10</font><font color="#000000">;<br/> x3dbl[</font><font color="#008000">12</font><font color="#000000">] := </font><font color="#008000">11</font><font color="#000000">; x3dbl[</font><font color="#008000">13</font><font color="#000000">] := </font><font color="#008000">12</font><font color="#000000">; x3dbl[</font><font color="#008000">14</font><font color="#000000">] := </font><font color="#008000">13</font><font color="#000000">; x3dbl[</font><font color="#008000">15</font><font color="#000000">] := </font><font color="#008000">14</font><font color="#000000">;<br/> </font><font color="#008000">// Set values of explanatory categorical series<br/> </font><font color="#000000"> x4cat[</font><font color="#008000">0</font><font color="#000000">] := </font><font color="#008000">1</font><font color="#000000">; x4cat[</font><font color="#008000">1</font><font color="#000000">] := </font><font color="#008000">1</font><font color="#000000">; x4cat[</font><font color="#008000">2</font><font color="#000000">] := </font><font color="#008000">1</font><font color="#000000">; x4cat[</font><font color="#008000">3</font><font color="#000000">] := </font><font color="#008000">1</font><font color="#000000">;<br/> x4cat[</font><font color="#008000">4</font><font color="#000000">] := </font><font color="#008000">1</font><font color="#000000">; x4cat[</font><font color="#008000">5</font><font color="#000000">] := </font><font color="#008000">1</font><font color="#000000">; x4cat[</font><font color="#008000">6</font><font color="#000000">] := </font><font color="#008000">1</font><font color="#000000">; x4cat[</font><font color="#008000">7</font><font color="#000000">] := </font><font color="#008000">2</font><font color="#000000">;<br/> x4cat[</font><font color="#008000">8</font><font color="#000000">] := </font><font color="#008000">2</font><font color="#000000">; x4cat[</font><font color="#008000">9</font><font color="#000000">] := </font><font color="#008000">2</font><font color="#000000">; x4cat[</font><font color="#008000">10</font><font color="#000000">] := </font><font color="#008000">2</font><font color="#000000">; x4cat[</font><font color="#008000">11</font><font color="#000000">] := </font><font color="#008000">2</font><font color="#000000">;<br/> x4cat[</font><font color="#008000">12</font><font color="#000000">] := </font><font color="#008000">3</font><font color="#000000">; x4cat[</font><font color="#008000">13</font><font color="#000000">] := </font><font color="#008000">3</font><font color="#000000">; x4cat[</font><font color="#008000">14</font><font color="#000000">] := </font><font color="#008000">3</font><font color="#000000">; x4cat[</font><font color="#008000">15</font><font color="#000000">] := </font><font color="#008000">3</font><font color="#000000">;<br/> </font><font color="#008000">// Determine maximum number of levels in tree<br/> </font><font color="#000000"> CART.TreeSizeSpecification.MaximumNumberOfLevels := </font><font color="#008000">3</font><font color="#000000">;<br/> </font><font color="#008000">// Determine minimum number of observations that can be in a tree node<br/> </font> CART.TreeSizeSpecification.MinimumNumberOfCases := <font color="#008000">2</font><font color="#000000">;<br/> </font><font color="#008000">// Consider each category as a separate attribute<br/> </font><font color="#000000"> CART.TreeSizeSpecification.ReduceCategories := </font><font color="#008080">True</font><font color="#000000">;<br/> </font><font color="#008000">// Set explained series<br/> </font><font color="#000000"> CART.Dependent.Value := y;<br/> </font><font color="#008000">// Set explanatory ordinal<br/> </font><font color="#000000"> CART.ExplanatoriesOrdered.Add().Value := x1;<br/> CART.ExplanatoriesOrdered.Add().Value := x2;<br/> CART.ExplanatoriesContinuous.Add().Value := x3dbl;<br/> CART.ExplanatoriesCategorical.Add().Value := x4cat;<br/> </font><font color="#008000">// Calculate and display values to console window<br/> </font><font color="#000000"> res := CART.Execute();<br/> ROCcurve := CART.ROCcurve;<br/> System.Diagnostics.Debug.WriteLine(CART.Errors);<br/> </font><font color="#008080">If</font><font color="#000000"> res <> </font><font color="#008000">0</font><font color="#000000"> </font><font color="#008080">Then</font><font color="#000000"><br/> System.Diagnostics.Debug.WriteLine(</font><font color="#800000">"Error occurred"</font><font color="#000000">);<br/> </font><font color="#008080">Else</font><font color="#000000"><br/> </font><font color="#008080">If</font><font color="#000000"> ROCcurve <> </font><font color="#008080">Null</font><font color="#000000"> </font><font color="#008080">Then</font><font color="#000000"><br/> System.Diagnostics.Debug.WriteLine(</font><font color="#800000">"Data of ROC curve:"</font><font color="#000000">);<br/> System.Diagnostics.Debug.Indent();<br/> System.Diagnostics.Debug.WriteLine(</font><font color="#800000">"Specificity:"</font><font color="#000000">);<br/> System.Diagnostics.Debug.Indent();<br/> OneMinusSpecificity := ROCcurve.OneMinusSpecificity;<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"> OneMinusSpecificity.Length - </font><font color="#008000">1</font><font color="#000000"> </font><font color="#008080">Do</font><font color="#000000"><br/> System.Diagnostics.Debug.WriteLine(OneMinusSpecificity[i]);<br/> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">For</font><font color="#000000">;<br/> System.Diagnostics.Debug.Unindent();<br/> System.Diagnostics.Debug.WriteLine(</font><font color="#800000">"Sensitivity:"</font><font color="#000000">);<br/> System.Diagnostics.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/> System.Diagnostics.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 criteria of classification quality<br/> </font><font color="#000000"> System.Diagnostics.Debug.Unindent();<br/> System.Diagnostics.Debug.Unindent();<br/> System.Diagnostics.Debug.WriteLine(</font><font color="#800000">" == Criteria of classification quality == "</font><font color="#000000">);<br/> System.Diagnostics.Debug.WriteLine(</font><font color="#800000">"Overall accuracy: "</font><font color="#000000"> + CART.RelevanceMeasure.Accuracy.ToString());<br/> System.Diagnostics.Debug.WriteLine(</font><font color="#800000">"F - estimate: "</font><font color="#000000"> + CART.RelevanceMeasure.F1.ToString());<br/> System.Diagnostics.Debug.WriteLine(</font><font color="#800000">"Number of truly positive values: "</font><font color="#000000"> + CART.RelevanceMeasure.TruePositive.ToString());<br/> System.Diagnostics.Debug.WriteLine(</font><font color="#800000">"Number of truly negative values: "</font><font color="#000000"> + CART.RelevanceMeasure.TrueNegative.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">;</font>
After executing the example, the console window will display ROC curve data and classification quality criteria.
See also: