K-Means Clustering
What is Clustering?
Grouping without labels
Clustering finds natural groups in unlabeled data. Slide k to change how many true clusters exist, then reveal them.
Step 1 of 6: What is Clustering?
Grouping without labels
Clustering finds natural groups in unlabeled data. Slide k to change how many true clusters exist, then reveal them.
Step 2 of 6: How K-Means Works
The algorithm step by step
We have unlabeled data and want to find k=3 clusters. The algorithm needs a way to group these points automatically.
Step 3 of 6: Assignment Step
Color by nearest centroid
Each point is assigned to the nearest centroid — creating Voronoi-like regions. Press Play or drag the slider.
Step 4 of 6: Update Step
Move centroids to their means
Centroids move to the mean of their assigned points — then we reassign. Watch the dashed arrows show displacement.
Step 5 of 6: Convergence
When assignments stop changing
K-means converges when no points change their assignment — typically in 5-15 iterations. Watch inertia drop.
Step 6 of 6: The Elbow Method
Choosing the right k
The elbow! At k=3, adding more clusters gives diminishing returns. This is usually the best choice.