k-Means Clustering

Classical models built from the math you already know

A map of two dozen unlabeled dots. No answers, no labels, and still the computer finds the groups. Every model built so far in this course learned from labeled examples: a price to match, a class to predict. k-Means throws the labels away entirely, guided by nothing except how close the points sit to one another.

k ice-cream trucks scatter around a town at the start of the season. Each morning, every truck drives to the exact centre of the customers it served the day before. Once the trucks resettle, a few customers now sit a touch closer to a different truck, so tomorrow's territories shift too. Repeat this every morning, and eventually the trucks stop moving: each one has parked itself at the centre of a stable little neighbourhood of customers. That whole routine, repeated until nothing moves, is k-Means.

Below are unlabeled points, plus k centre markers you can drag anywhere. Press step and watch two things happen in turn: first every point takes on the colour of whichever centre it is nearest to, then the centres glide to the average position of the points that just picked them. Nothing here is precomputed. Drag a point, drag a centre, change k, and press step again to watch it re-sort the data from wherever you left it.

Where this lives in MLClustering with zero labels shows up constantly outside a classroom. Grouping customers by purchase behaviour into a handful of segments, compressing an image by replacing every pixel's colour with its nearest of k representative colours, and finding a first rough grouping in a dataset before any labels exist all run on this exact loop. The assign-then-move routine also previews a pattern that…
▶ k-Means Clustering
← Boosting: Learning from Your MistakesHow Many Clusters? Elbow & Silhouette →