This is a small program which demonstrates how the k-means clustering algorithm works in two dimensions. For more information, Wikipedia has a good description of the algorithm.
The program starts with some randomly-generated data. Use the mouse to choose the initial locations of the cluster centroids. Then press ‘space’ to iterate the algorithm and see how it converges on a solution.
- ‘r’ – reset (re-create the random data points)
- ‘space’ – iterate the algorithm
- mouse click – choose a location for a new cluster centroid
Application (contains binaries for Windows, Mac and Linux): KMeans_app
Source code (written with Processing): KMeans-src