ClassCount: Integer;
The ClassCount property returns the number of classes obtained as the result of method calculation.
The IDataMining.FilledDependent property returns total classification of objects.
To execute the example, add links to the MathFin, Stat system assemblies.
// Main procedure
Sub UserDiscrAn;
Var
DA: SmDiscriminantAnalysis;
y: Array[60] Of Integer;
x1, x2, x3, x4, x5, x6, x7, x8: Array[60] Of Double;
Ex: ISlSeries;
res, i, j: Integer;
indx0: Double;
resM: Array Of Integer;
str: String;
Begin
DA := New SmDiscriminantAnalysis.Create;
// Source data: sixty objects with eight attributes
For i := 0 To 59 Do
x1[i] := Math.RandBetween(95, 104);
x2[i] := Math.RandBetween(95, 104);
x3[i] := Math.RandBetween(95, 104);
x4[i] := Math.RandBetween(95, 104);
x5[i] := Math.RandBetween(95, 104);
x6[i] := Math.RandBetween(95, 104);
x7[i] := Math.RandBetween(95, 104);
x8[i] := Math.RandBetween(95, 104);
End For;
// explained series values
For i := 0 To 39 Do
y[i] := Math.RandBetweenI(1, 5);
End For;
For i := 40 To 59 Do
y[i] := -1;
End For;
// 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;
// Calculate and display results
If DA.Execute = 0 Then
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);
str := "===========================" + #13 + #10;
Debug.WriteLine(str + " == Grand average == ");
Print(DA.TotalAverage, DA.TotalAverage.Rank);
Debug.WriteLine(" == Intraclass average == ");
Print(DA.WithinAverage, DA.WithinAverage.Rank);
Debug.WriteLine(str + " == Common standard deviation == ");
Print(DA.TotalStdDev, DA.TotalStdDev.Rank);
Debug.WriteLine(" == Intraclass standard deviation == ");
Print(DA.WithinStdDev, DA.WithinStdDev.Rank);
Debug.WriteLine(str + " == Common correlation == ");
Print(DA.TotalCorrelation, DA.TotalCorrelation.Rank);
Debug.WriteLine(" == Intraclass correlation == ");
Print(DA.WithinCorrelation, DA.WithinCorrelation.Rank);
Debug.WriteLine(" == Averaged intraclass correlation == ");
Print(DA.PooledWithinCorrelation, DA.PooledWithinCorrelation.Rank);
Debug.WriteLine(str + " == Common covariance == ");
Print(DA.TotalCovariance, DA.TotalCovariance.Rank);
Debug.WriteLine(" == Intraclass covariance == ");
Print(DA.WithinCovariance, DA.WithinCovariance.Rank);
Debug.WriteLine(" == Averaged intraclass covariance == ");
Print(DA.PooledWithinCovariance, DA.PooledWithinCovariance.Rank);
Debug.WriteLine(str + " == Canonical discriminant function coefficients == ");
Debug.WriteLine(" = standardized = ");
Print(DA.StdDiscriminantFuncs, DA.StdDiscriminantFuncs.Rank);
Debug.WriteLine(" = non-standardized = ");
Print(DA.NonStdDiscriminantFuncs, DA.NonStdDiscriminantFuncs.Rank);
Debug.WriteLine(str+"==Wilkesstatistic=="); Print(DA.WilkesStatistics, DA.WilkesStatistics.Rank);
Debug.WriteLine(str + " == Fisher functions == ");
Print(DA.FishersFuncs, DA.FishersFuncs.Rank);
Debug.WriteLine(str + " == Structure matrix == ");
Print(DA.StructuralMatrix, DA.StructuralMatrix.Rank);
Debug.WriteLine(str + " == Eigenvalues == ");
Print(DA.EigenValues, DA.EigenValues.Rank);
Debug.WriteLine(str + " == Classification of variables == ");
For i := 0 To DA.FinallyExplained.Length - 1 Do
indx0 := DA.FinallyExplained[i];
Debug.WriteLine(i.ToString + ". " + indx0.ToString);
End For;
End If;
End Sub UserDiscrAn;
// Data output procedure
Sub Print(a: Array Of Double; d2: integer);
Var
ci: ICultureInfo;
i, j: integer;
s: string;
Begin
ci := CultureInfo.Current;
If d2 = 2 Then
For i := 0 To a.GetUpperBound(2) Do
s := "";
For j := 0 To a.GetUpperBound(1) Do
If Double.IsNan(a[j, i]) Then
s := s + " " + " - ";
Else
s := s + " " + ci.FormatDoublePrec(a[j, i], 2);
End If;
End For;
Debug.WriteLine(s);
End For;
Else
For i := 0 To a.GetUpperBound(1) Do
If Double.IsNan(a[i]) Then
s := s + " " + " - ";
Else
s := s + " " + ci.FormatDoublePrec(a[i], 2);
End If;
End For;
Debug.WriteLine(s);
End If;
End Sub Print;
After executing the main procedure, discriminatory analysis is performed for the specified data, analysis results are displayed to the console window.
See also: