K-means clustering needs to be told how many clusters, k, to look for
before it can run — it will happily produce a tidy-looking partition for almost any
k you give it, even a wrong one. This lab runs real k-means on a small
3D point cloud and shows the two classic tools people use to pick a sensible
k: the elbow method (inertia vs. k) and the
silhouette score (a per-point measure of how well-matched a point is
to its own cluster vs. the next closest one).
k rises, so the "elbow" (where the drop stops being dramatic) is the signal, not the lowest value.s = (b − a) / max(a, b), where a is the mean distance to points in its own cluster and b is the mean distance to the nearest other cluster. Averaged over all points, it peaks near a genuinely good k and can even fall as k keeps rising.k the slider is set to, so you can see both curves respond as you move it.
Silhouette scores range from −1 to 1. A negative score for a point means it is, on
average, closer to a neighbouring cluster than to its own — a strong hint that either
the point or the whole choice of k is wrong.
A live k-means clustering lab: run clustering on a 3D point cloud, sweep the number of clusters k, and watch the elbow (inertia) curve and the silhouette-score curve build in real time.
Inertia always decreases as k grows, so the "elbow" — not the minimum — is the signal. Silhouette score instead peaks near a genuinely good k, and can even fall as k keeps rising, giving a second, independent check.
Pick a dataset, drag the k slider or hit Sweep to watch both bar charts respond, and switch point colouring to silhouette value to see exactly which points are poorly matched to their cluster.
On the "Uniform noise" dataset there is no real cluster structure at all — both curves go nearly flat, which is itself a useful diagnostic: no k is a good k.