ClusteringSample

k-means

Splits points into k groups by alternately assigning points to the nearest centre and moving centres to their mean.

Synthetic data, generated and trained in your browser.

Try this

  1. 01Press Step repeatedly and watch the assign-then-move cycle.
  2. 02On Uneven blobs, set k = 4 with Random initialisation and press New start a few times: some runs get stuck.
  3. 03Try Moons: k-means can only draw straight borders, so it cuts each moon in half.

How it works

  1. 1Place k centres (randomly, or spread out with k-means++).
  2. 2Assign every point to its nearest centre.
  3. 3Move each centre to the mean of its points.
  4. 4Repeat the last two steps until nothing moves.

What the controls teach

Clusters k
Number of clusters. The elbow chart shows where adding more stops paying off.
Initialisation
Random starts can land badly; k-means++ spreads the starting centres out.

Use it when

  • Compact, roughly round clusters
  • Large datasets (it is fast)

Avoid it when

  • Non-convex shapes
  • Clusters of very different sizes or densities

More in Clustering