Count: Integer;
The Count property returns number of clusters.
Sub Main;
Var
hc: SmHierarchicalClusterAnalysis;
Obj: ISlSeries;
x1: Array Of Double;
Dist: ISlDistance;
res, i, j: Integer;
D: Double;
masDouble: Array Of Double;
Cls: IClustersType;
Cl: IClusterType;
Begin
hc := New SmHierarchicalClusterAnalysis.Create;
x1 := New Double[3];
//add characteristics, in this case 5 objects with 3 characteristics
x1[0] := 1; x1[1] := 1; x1[2] := 1;
Obj := hc.Objects;
Obj.Add.Value := x1;
x1[0] := 2; x1[1] := 3; x1[2] := 2;
Obj.Add.Value := x1;
x1[0] := 3; x1[1] := 6; x1[2] := 3;
Obj.Add.Value := x1;
x1[0] := 4; x1[1] := 8; x1[2] := 10;
Obj.Add.Value := x1;
x1[0] := 5; x1[1] := 8; x1[2] := 0;
Obj.Add.Value := x1;
hc.ClusterLink := ClusterLinkType.Centroid;
hc.ClusterCount := 2;
Dist := hc.Distance;
Dist.Type := ObjectDistanceType.EuclideanSqr;
Dist.Standartization := StandartizationType.ScaleStd;
hc.DendogramOrientation := DendogramOrientationType.East;
res := hc.Execute;
If res <> 0 Then
Debug.WriteLine(hc.Errors);
Else
Debug.WriteLine("=== Cluster centers ===");
Cls := hc.Clusters;
For i := 0 To Cls.Count - 1 Do //by clusters
Debug.Write("Cluster №" + i.ToString + " ");
Cl := Cls.Item(i);
masDouble := Cl.Center;
For j := 0 To masDouble.Length-1 Do //by all characteristics in a cluster
d := masDouble[j];
Debug.Write(d.ToString + ", ");
End For;
Debug.WriteLine("");
End For;
End If;
End Sub Main;
After executing the example the console window displays cluster centers:
Module execution started
=== Cluster centers===
Cluster №0 1.5, 2, 1.5,
Cluster №1 4, 7.333333333333333, 4.333333333333333,
Module execution finished
See also: