Classical ML

K-means clustering, visualized

K-means is one of the most widely used unsupervised learning algorithms: given unlabelled points, it groups them into k clusters. It alternates two simple steps — assign each point to its nearest cluster centre, then move each centre to the average of its points — until things stop changing.

It's a perfect first taste of how an algorithm can find structure in data with no labels at all, and the assign/update rhythm shows up again in more advanced methods.

Step through assign → update

Iteration 0

keep stepping

Each ✕ chases the middle of the points that chose it.

Notice: k-means never sees the "true" clusters — it only ever minimises distance to the nearest ✕. 12 points, 3 centroids.

Free · runs entirely in your browser · nothing to install

How to use it

  1. Start with rough, deliberately-wrong cluster centres.
  2. Run the assign step: each point joins its nearest centre.
  3. Run the update step: each centre jumps to the middle of its points. Repeat until it settles.

What you'll take away

  • The difference between supervised and unsupervised learning.
  • Why k-means converges through repeated assign/update rounds.
  • How the starting positions can change the final clusters.

Want to actually build this?

This demo is one moment inside a full Math to Machine lesson — predict, build, and explain the concept, with an AI tutor that gives hints, not answers. The first five lessons are free.

FAQ

What is k-means clustering?
It's an algorithm that partitions data into k groups by repeatedly assigning points to the nearest cluster centre and then recomputing each centre as the mean of its assigned points, until the assignments stop changing.
Do you need labelled data for k-means?
No. K-means is unsupervised — it finds groupings using only the positions of the data points, with no labels telling it the correct answer.

More Classical ML tools