All Bundles

KMeans

K-Means clustering algorithm

Operations

Code example:

points := Vector->New()<KMeansPoint>;
points->AddBack(KMeansPoint->New(9.78, 7.86));
points->AddBack(KMeansPoint->New(0.81, 0.77));
points->AddBack(KMeansPoint->New(8.82, 5.48));
points->AddBack(KMeansPoint->New(1.80, 0.43));
points->AddBack(KMeansPoint->New(6.16, 6.60));
points->AddBack(KMeansPoint->New(6.51, 8.72));
points->AddBack(KMeansPoint->New(1.10, 2.56));
points->AddBack(KMeansPoint->New(7.89, 4.49));
points->AddBack(KMeansPoint->New(3.33, 2.89));
points->AddBack(KMeansPoint->New(0.74, 3.99));
points->AddBack(KMeansPoint->New(3.15, 1.70));
points->AddBack(KMeansPoint->New(0.55, 6.27));

kmeans := KMeans->New(2, 0.0, 10.0, points);
clusters := kmeans->Cluster();

each(i : clusters) {
  cluster := clusters[i];
  "G{$i}->{$cluster}"->PrintLine();
};

New

Constructor

New(k:Int, min:Float, max:Float, points:Vector<KMeansPoint>)
Parameters
NameTypeDescription
kIntk number of clusters
minFloatminimum starting centroid point
maxFloatmaximum starting centroid point
pointsVector<KMeansPoint>input data points

Cluster

Cluster input points

method : public : Cluster() ~ Vector[]<KMeansPoint>
Return
TypeDescription
Vector[]<KMeansPoint>clustered input points

LoadData

Load input data point from a CSV file

function : LoadData(filename:String) ~ Vector<KMeansPoint>
Parameters
NameTypeDescription
filenameStringinput filename

Return
TypeDescription
Vector<KMeansPoint>input data points