FilledDependent: Array;
FilledDependent: System.Array;
The FilledDependent property returns predicted classification.
To get summary results of classification, use the ISmRandomForest.ClassificationSummary property.
Add a link to the Stat system assembly.
Sub UserProc;
Var
rf: SmRandomForest;
Y, CatX: Array[16] Of Integer;
X: Array[16] Of Double;
res, i, j: Integer;
s: string;
Explanatories: ISlSeries;
Explan: ISlSerie;
ExplInt: ISlSeriesInt;
ExplanInt: ISlSerieInt;
CatList: Array Of Integer;
Begin
rf := New SmRandomForest.Create;
// Set explained series
Y[00] := 0; Y[08] := 1;
Y[01] := 1; Y[09] := 2;
Y[02] := 1; Y[10] := 0;
Y[03] := 0; Y[11] := 2;
Y[04] := 1; Y[12] := 1;
Y[05] := 2; Y[13] := 2;
Y[06] := 1; Y[14] := 2;
Y[07] := 2; Y[15] := 0;
rf.Dependent.Value := Y;
// Set explanatory series (categorical)
CatX[00] := 1; CatX[08] := 1;
CatX[01] := 3; CatX[09] := 2;
CatX[02] := 1; CatX[10] := 3;
CatX[03] := 3; CatX[11] := 2;
CatX[04] := 1; CatX[12] := 3;
CatX[05] := 2; CatX[13] := 1;
CatX[06] := 1; CatX[14] := 1;
CatX[07] := 2; CatX[15] := 3;
ExplInt := rf.ExplanatoriesCategorical;
ExplInt.Clear;
ExplanInt := ExplInt.Add;
ExplanInt.Id := "Categorical_X";
ExplanInt.Name := "CatX";
ExplanInt.Value := CatX;
// Set explanatory series (quantitative)
X[00] := 34.13; X[08] := 29.27;
X[01] := 21.52; X[09] := 23.39;
X[02] := 25.43; X[10] := 28.28;
X[03] := 43.42; X[11] := 43.55;
X[04] := 40.19; X[12] := 44.80;
X[05] := 24.97; X[13] := 23.23;
X[06] := 20.57; X[14] := 37.14;
X[07] := 30.81; X[15] := 27.44;
Explanatories := rf.ExplanatoriesContinuous;
Explanatories.Clear;
Explan := Explanatories.Add;
Explan.Id := "Continuous_X";
Explan.Name := "X";
Explan.Value := X;
// Forest size
rf.ForestSize := 20;
rf.LearningSamplePortion := 0.6;
// Trees size
res := rf.Execute;
If (res = 0) Then
Debug.WriteLine(" === Probability ===");
Debug.Indent;
For i := 0 To rf.Probability.GetUpperBound(1) Do
For j := 0 To rf.Probability.GetUpperBound(2) Do
s := s + rf.Probability[i, j].ToString + " ";
End For;
Debug.WriteLine(s);
s := "";
End For;
Debug.Unindent;
Debug.WriteLine(" === Predicted classification ===");
Debug.Indent;
For i := 0 To rf.FilledDependent.Length - 1 Do
Debug.WriteLine((i + 1).ToString + ". " + rf.FilledDependent[i].ToString);
End For;
Debug.Unindent;
Debug.WriteLine("=== Original values of categorical data series ===");
Debug.Indent;
For i := 0 To ExplanInt.Value.Length - 1 Do
Debug.WriteLine((i + 1).ToString + ". " + ExplanInt.OriginalValue[i].ToString);
End For;
Debug.Unindent;
Debug.WriteLine(" === Summary results of classification ===");
Debug.Indent;
s := "";
For i := 0 To rf.ClassificationSummary.GetUpperBound(1) Do
For j := 0 To rf.ClassificationSummary.GetUpperBound(2) Do
s := s + rf.ClassificationSummary[i, j].ToString + " ";
End For;
Debug.WriteLine(s);
s := "";
End For;
Debug.Unindent;
// Display list of categories
CatList := rf.CategoriesList;
If CatList.Length > 0 Then
Debug.WriteLine("List of categories:"); Debug.Indent;
For i := 0 To CatList.Length - 1 Do
Debug.WriteLine(CatList[i]);
End For;
Debug.Unindent;
End If;
Else
Debug.WriteLine(rf.Errors);
End If;
End Sub UserProc;
After executing the example the console window displays:
Probability.
Predicted classification.
Original values of categorical data series.
Summary results of classification.
List of categories.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Stat;
…
Public Shared Sub Main(Params: StartParams);
Var
rf: SmRandomForest;
Y, CatX: Array[16] Of Integer;
X: Array[16] Of Double;
res, i, j: Integer;
s: string;
Explanatories: ISlSeries;
Explan: ISlSerie;
ExplInt: ISlSeriesInt;
ExplanInt: ISlSerieInt;
Probability, FilledDependent, OriginalValue, ClassificationSummary, CatList: System.Array;
Begin
rf := New SmRandomForest.Create();
// Set explained series
Y[00] := 0; Y[08] := 1;
Y[01] := 1; Y[09] := 2;
Y[02] := 1; Y[10] := 0;
Y[03] := 0; Y[11] := 2;
Y[04] := 1; Y[12] := 1;
Y[05] := 2; Y[13] := 2;
Y[06] := 1; Y[14] := 2;
Y[07] := 2; Y[15] := 0;
rf.Dependent.Value := Y;
// Set explanatory series (categorical)
CatX[00] := 1; CatX[08] := 1;
CatX[01] := 3; CatX[09] := 2;
CatX[02] := 1; CatX[10] := 3;
CatX[03] := 3; CatX[11] := 2;
CatX[04] := 1; CatX[12] := 3;
CatX[05] := 2; CatX[13] := 1;
CatX[06] := 1; CatX[14] := 1;
CatX[07] := 2; CatX[15] := 3;
ExplInt := rf.ExplanatoriesCategorical;
ExplInt.Clear();
ExplanInt := ExplInt.Add();
ExplanInt.Id := "Categorical_X";
ExplanInt.Name := "CatX";
ExplanInt.Value := CatX;
// Set explanatory series (quantitative)
X[00] := 34.13; X[08] := 29.27;
X[01] := 21.52; X[09] := 23.39;
X[02] := 25.43; X[10] := 28.28;
X[03] := 43.42; X[11] := 43.55;
X[04] := 40.19; X[12] := 44.80;
X[05] := 24.97; X[13] := 23.23;
X[06] := 20.57; X[14] := 37.14;
X[07] := 30.81; X[15] := 27.44;
Explanatories := rf.ExplanatoriesContinuous;
Explanatories.Clear();
Explan := Explanatories.Add();
Explan.Id := "Continuous_X";
Explan.Name := "X";
Explan.Value := X;
// Forest size
rf.ForestSize := 20;
rf.LearningSamplePortion := 0.6;
// Trees size
res := rf.Execute();
If (res = 0) Then
System.Diagnostics.Debug.WriteLine(" === Probability ===");
System.Diagnostics.Debug.Indent();
Probability := rf.Probability;
For i := 0 To Probability.GetUpperBound(1) Do
For j := 0 To Probability.GetUpperBound(0) Do
s := s + Probability[j, i].ToString() + " ";
End For;
System.Diagnostics.Debug.WriteLine(s);
s := "";
End For;
System.Diagnostics.Debug.Unindent();
System.Diagnostics.Debug.WriteLine(" === Predicted classification ===");
System.Diagnostics.Debug.Indent();
FilledDependent := rf.FilledDependent;
For i := 0 To FilledDependent.Length - 1 Do
System.Diagnostics.Debug.WriteLine((i + 1).ToString() + ". " + FilledDependent[i].ToString());
End For;
System.Diagnostics.Debug.Unindent();
System.Diagnostics.Debug.WriteLine("=== Original values of categorical data series ===");
System.Diagnostics.Debug.Indent();
OriginalValue := ExplanInt.OriginalValue;
For i := 0 To ExplanInt.Value.Length - 1 Do
System.Diagnostics.Debug.WriteLine((i + 1).ToString() + ". " + OriginalValue[i].ToString());
End For;
System.Diagnostics.Debug.Unindent();
System.Diagnostics.Debug.WriteLine(" === Summary results of classification ===");
System.Diagnostics.Debug.Indent();
s := "";
ClassificationSummary := rf.ClassificationSummary;
For i := 0 To ClassificationSummary.GetUpperBound(1) Do
For j := 0 To ClassificationSummary.GetUpperBound(0) Do
s := s + ClassificationSummary[j, i].ToString() + " ";
End For;
System.Diagnostics.Debug.WriteLine(s);
s := "";
End For;
System.Diagnostics.Debug.Unindent();
// Display list of categories
CatList := rf.CategoriesList;
If CatList.Length > 0 Then
System.Diagnostics.Debug.WriteLine("List of categories:");
System.Diagnostics.Debug.Indent();
For i := 0 To CatList.Length - 1 Do
System.Diagnostics.Debug.WriteLine(CatList[i]);
End For;
System.Diagnostics.Debug.Unindent();
End If;
Else
System.Diagnostics.Debug.WriteLine(rf.Errors);
End If;
End Sub;
See also: