K-Means
AvailableRun a clustering algorithm iteration by iteration and watch the centroids move.
Description
Qué haceSplits a set of points into k groups, trying to keep the points within each group as close together as possible.
Para qué sirveDiscovering structure or segments in unlabeled data (customers, documents, images) when you don't know in advance which group each item belongs to.
Groups points into k clusters by alternating assignment and centroid updates. Synthetic dataset; the algorithm only ever sees coordinates, never the original labels.
Assignment, update, and inertia
Assignment
Each point joins the nearest centroid by Euclidean distance.
Update
Each centroid moves to the average of the points assigned to it. This is Lloyd's algorithm.
Inertia
Σ ‖point − its centroid‖²
Measures how compact the clusters are. It never goes up from one assignment to the next.
Choosing k
It’s an external decision: the “Elbow method” sweeps k comparing inertia.
What the chart shows
Phase / iteration
Where in the assignment-update alternation the run currently is, and how many have happened so far.
Centroids
Marked larger, with a ring and a number (C0, C1...). The dashed line shows their most recent movement.
Strengths and limits
Simple and fast
O(k · n) per iteration
Every point belongs to exactly one cluster. Works well with roughly spherical groups of similar size.
Only convex regions
Doesn't separate structures like concentric rings — see the “Poor fit” case.
Sensitive to outliers
The mean gets pulled by extreme values — see the “Outlier sensitivity” case.
Sensitive to initialization
The same dataset can converge differently depending on the seed. k-means++ reduces the risk, without eliminating it.
Playground
Training
- Unassigned point
- Cluster 0 (centroid C0)
- Cluster 1 (centroid C1)
- Cluster 2 (centroid C2)
Each point takes the color and shape of its nearest centroid's cluster (Euclidean distance). The dashed accent line shows how much each centroid moved in the last update.
Run state
- Phase
- Ready
- Iteration
- 0 / 100
- Current inertia
- —
Initial centroids computed. Step forward to start assigning points.
Dataset generation
Changing these controls generates a new synthetic dataset and resets the run.
Seed for the deterministic generator.
Standard deviation of each group's Gaussian noise.
K-Means
Number of clusters. Limited to the palette's color/shape combinations.
How many different initializations to try, keeping the one with the lowest final inertia. n_init=1 is the original behavior: a single run, no comparison.
Educational cases
Inertia
Run
Status: Ready. Initial centroids computed. Step forward to start assigning points.
Run controls are available. Shortcut: spacebar starts or pauses (if focus isn't in a text field or control).