How to use the K-Means Clustering Visualizer
- 1. Add pointsClick the board, edit the list, or press Random blobs.
- 2. Choose k and a seedPick how many clusters to find and a seed for the start.
- 3. Run k-meansWatch the centres move until nothing changes, then read the summary.
How k-means works
k-means repeats two steps until the clusters stop changing:
- Assign every point to its nearest centre (Euclidean distance).
- Update each centre to the mean of the points assigned to it.
For example, if a cluster holds (1, 1), (2, 1) and (1, 2), its new centre is ((1 + 2 + 1) ÷ 3, (1 + 1 + 2) ÷ 3) = (1.33, 1.33). The algorithm minimises inertia, the sum of squared distances from points to their centres. The default board has 24 points in three clear groups, and with k = 3 the tool finds cluster sizes of 8, 8, 8.
Things to try
- Change the seed. Starting centres are chosen with k-means++, which spreads them out, but a different start can still end in a different answer on messy data.
- Run k = 2 to 6 and note the inertia each time. Where the drop flattens out, the elbow, is a reasonable k.
- Make odd shapes like a ring or a long strip. k-means assumes round, similar-sized clusters and splits these badly; DBSCAN suits them better.
- Add an outlier far away and watch it drag a centre.
In Python this is KMeans(n_clusters=3, n_init=10).fit(X) from scikit-learn, which runs several seeds and keeps the best. Always scale features first, because k-means uses raw distances; see the normalization calculator. Compare with a supervised method in the KNN visualizer.
Frequently asked questions
Can I use the keyboard instead of clicking?
Yes. Type points into the list as x, y per line; the board updates as you type.
Why do I sometimes get an empty cluster?
If no point is nearest to a centre, it keeps its old position. Try another seed or a smaller k.
Is the K-Means Clustering Visualizer free?
Yes, the K-Means Clustering Visualizer is free. The first time you run k-means for the first time, you are asked for your name and WhatsApp number once. After that, this and every other Uncodemy tool opens straight away without the form.