The algorithm is simple:
- Bind each data point to the closest centroid:
- Adjust each centroid's position to the mean of its bound data points:
- And cycle through these until there is no more change
Here is a quick example with random points:
The code is in my github k-means-octave repository.