Saturday, 20 December 2014

k-means clustering using algorithm AS 136

This blog post implements k-means clustering using algorithm AS 136, as devised by Hartigan and Wong. The implementation was made considerably easier by the work of J Burkardt here, who has translated the original Fortran to C,C++ and Matlab, as well as other flavours of Fortran.

Please enter the numbers in the text areas below - either one number per line or two or more comma separated numbers per line. There must be no new line after the last number.

Alternatively you can choose to load a CSV file, which can be one or more columns of numbers only (the number of columns is equal to the spatial dimension). Before loading the CSV file, you need to fill in the number of spatial dimensions.

To perform the k-means clustering, please enter the number of clusters and the maximum number of iterations in the appropriate fields, then press the button labelled "Perform k-means clustering" below - the results will populate the textareas below labelled "Output" and "Centroid values". The "Output" textarea will list the sample values and the cluster/centroid index each sample belongs to, while the "Centroid values" textarea will list the centroid index and the value of the centroids (or cluster centres). Note that the first index of the cluster centres starts at 0.

If the number of spatial dimensions is either 1 or 2, then the data points will be plotted below and coloured according to cluster membership.

Should the algorithm not converge within the maximum number of iterations specified, an alert will be generated to this effect.

Enter number of spatial dimensions:-


Enter number of clusters (k value):-

Enter maximum number of iterations:-

Centroid values:-

Cluster Visualisation for spatial dimensions 1 or 2