K-Means Clustering — Magical Learning Lab

Group similar things into k colourful families! Choose k, watch centroids dance, and see how points find their best cluster. Toggle 2D/3D, switch datasets, and explore the Elbow Method.

1. Choose k
2. Initialize
3. Assign
4. Update

Play Controls

Blobs Two Moons Rings
3
Step
Current SSE
Centroids
Points
Switch to 3D Magic
What are we minimizing?

K-Means pulls each point towards the nearest center. We measure goodness with SSE (sum of squared errors). Smaller is better!

Interactive Visualizer
2D Constellation
Unassigned C1 C2 C3 C4 C5
Elbow Method — choose a good k

Look for the “elbow”: the point where adding more clusters no longer improves SSE a lot.

Pick k — choose how many groups you expect (try 2–6).
Initialize — place k starting centroids (random).
Assign — each point joins the nearest centroid.
Update — move each centroid to the average of its points.
Repeat — Assign ↔ Update until centroids barely move.
Everyday Examples