← Back to timeline
Classical ML1957interactive demo live

k-Means

Cluster around centroids

k-Means finds groups in unlabeled data by alternating between cluster assignment and centroid updates.

k-Means Demo

Two alternating moves: assign every point to its nearest centroid, then update each centroid to the average of its assigned points. Click the chart to add a point. Step manually to feel the rhythm, then run.

live demo

click chart to add a point · next move: assign

k
3
Iter
0
Inertia
Number of clusters (k)
Run

The two moves

assign: each point picks the closest centroid.
update: each centroid moves to the average of its assigned points.
Repeat. Both moves can only decrease (or hold) inertia — so the algorithm always converges.

Why initialization matters

Bad initial centroids can land in a local minimum and look stuck. This demo uses a k-means++ flavoured pick (first centroid random, the rest farthest-from-existing) so the first run looks sensible.