RelevanceMeasure: IBinaryModelRelevanceMeasure;
RelevanceMeasure: Prognoz.Platform.Interop.Stat.IBinaryModelRelevanceMeasure;
The RelevanceMeasure property returns binary classification quality criteria.
Criteria of classification quality are calculated, if explanatory series is binary.
To execute the example, add links to the MathFin, Stat system assemblies.
Sub UserProc;
Var
DA: SmDiscriminantAnalysis;
y, x1, x2, x3, x4, x5, x6, x7, x8: Array[60] Of Double;
Ex: ISlSeries;
res, i, j: Integer;
resM: Array Of Integer;
str: String;
Begin
DA := New SmDiscriminantAnalysis.Create;
// Initial data: sixty objects with eight attributes
For i := 0 To 59 Do
x1[i] := Math.RandBetween(0, 100);
x2[i] := Math.RandBetween(0, 100);
x3[i] := Math.RandBetween(0, 100);
x4[i] := Math.RandBetween(0, 100);
x5[i] := Math.RandBetween(0, 100);
x6[i] := Math.RandBetween(0, 100);
x7[i] := Math.RandBetween(0, 100);
x8[i] := Math.RandBetween(0, 100);
End For;
// Explained series values
For i := 0 To 59 Do
y[i] := Math.RandBetweenI(0, 1);
End For;
// Set explained variable
DA.Dependent.Value := y;
// Set explanatory variables
Ex := DA.Explanatories;
Ex.Add.Value := x1; Ex.Add.Value := x5;
Ex.Add.Value := x2; Ex.Add.Value := x6;
Ex.Add.Value := x3; Ex.Add.Value := x7;
Ex.Add.Value := x4; Ex.Add.Value := x8;
// Run calculation and output results
res := DA.Execute;
If res <> 0 Then
Debug.WriteLine(DA.Errors);
Else
Debug.WriteLine(" == Summary results of classification == ");
res := DA.ClassCount;
Debug.WriteLine("Number of classes: " + res.ToString);
resM := DA.ClassificationSummary;
For i := 0 To res - 1 Do
For j := 0 To res - 1 Do
str := str + " " + (resM[i, j] As Integer).ToString;
End For;
str := str + " | " + (resM[i, res] As Integer).ToString;
Debug.WriteLine(str);
str := "";
End For;
str := "- - - - - - - - ";
Debug.WriteLine(str);
str := "";
For j := 0 To DA.ClassCount - 1 Do
str := str + " " + (resM[res, j] As Integer).ToString;
End For;
str := str + " | " + (resM[res, res] As Integer).ToString;
Debug.WriteLine(str);
// Display classification quality criteria
Debug.WriteLine(" == Classification quality criteria == ");
Debug.WriteLine("Overall accuracy: " + DA.RelevanceMeasure.Accuracy.ToString);
Debug.WriteLine("F - estimation: " + DA.RelevanceMeasure.F1.ToString);
Debug.WriteLine("Accuracy of positive result: " + DA.RelevanceMeasure.Precision.ToString);
Debug.WriteLine("Accuracy of positive result: " + DA.RelevanceMeasure.Recall.ToString);
End If;
End Sub UserProc;
Imports Prognoz.Platform.Interop.MathFin;
Imports Prognoz.Platform.Interop.Stat;
…
Public Shared Sub Main(Params: StartParams);
Var
DA: SmDiscriminantAnalysis;
y, x1, x2, x3, x4, x5, x6, x7, x8: Array[60] Of double;
Ex: ISlSeries;
res, i, j: integer;
resM: System.Array;
str: string;
m: Prognoz.Platform.Interop.MathFin.MathClass;
Begin
DA := New SmDiscriminantAnalysis.Create();
m := New Prognoz.Platform.Interop.MathFin.MathClass.Create();
// Initial data: sixty objects with eight attributes
For i := 0 To 59 Do
x1[i] := m.RandBetween(0, 100);
x2[i] := m.RandBetween(0, 100);
x3[i] := m.RandBetween(0, 100);
x4[i] := m.RandBetween(0, 100);
x5[i] := m.RandBetween(0, 100);
x6[i] := m.RandBetween(0, 100);
x7[i] := m.RandBetween(0, 100);
x8[i] := m.RandBetween(0, 100);
End For;
// Explained series values
For i := 0 To 59 Do
y[i] := m.RandBetweenI(0, 1);
End For;
// Set explained variable
DA.Dependent.Value := y;
// Set explanatory variables
Ex := DA.Explanatories;
Ex.Add().Value := x1; Ex.Add().Value := x5;
Ex.Add().Value := x2; Ex.Add().Value := x6;
Ex.Add().Value := x3; Ex.Add().Value := x7;
Ex.Add().Value := x4; Ex.Add().Value := x8;
// Run calculation and output results
res := DA.Execute();
If res <> 0 Then
System.Diagnostics.Debug.WriteLine(DA.Errors);
Else
System.Diagnostics.Debug.WriteLine(" == Summary classification results == ");
res := DA.ClassCount;
System.Diagnostics.Debug.WriteLine("Number of classes: " + res.ToString());
resM := DA.ClassificationSummary;
For i := 0 To res - 1 Do
For j := 0 To res - 1 Do
str := str + " " + (resM[i, j] As Integer).ToString();
End For;
str := str + " | " + (resM[i, res] As Integer).ToString();
System.Diagnostics.Debug.WriteLine(str);
str := "";
End For;
str := "- - - - - - - - ";
System.Diagnostics.Debug.WriteLine(str);
str := "";
For j := 0 To DA.ClassCount - 1 Do
str := str + " " + (resM[res, j] As Integer).ToString();
End For;
str := str + " | " + (resM[res, res] As Integer).ToString();
System.Diagnostics.Debug.WriteLine(str);
// Display classification quality criteria
System.Diagnostics.Debug.WriteLine(" == Classification quality results == ");
System.Diagnostics.Debug.WriteLine("Overall accuracy: " + DA.RelevanceMeasure.Accuracy.ToString());
System.Diagnostics.Debug.WriteLine("F - estimate: " + DA.RelevanceMeasure.F1.ToString());
System.Diagnostics.Debug.WriteLine("Accuracy of positive result: " + DA.RelevanceMeasure.Precision.ToString());
System.Diagnostics.Debug.WriteLine("Completeness of positive result: " + DA.RelevanceMeasure.Recall.ToString());
End If;
End Sub;
After executing the example, the console window will display classification results and its quality criteria.
See also: