A delivery company wants to split 10,000 addresses into eight driver zones. K-means starts by dropping eight centers onto the map, often at randomly chosen addresses. Each address joins its nearest center. Each center then moves to the middle of its addresses. Repeat assign-and-move until the centers stop shifting, and the result is eight compact zones.
It is one of the oldest and simplest cluster analysis methods, simple enough that people reinvent it. In episode 41 at 5:52, the narrator explains that Writer’s Melisa Russak built something that turned out to be essentially k-means clustering in her first data science job, before she learned the algorithm had existed for decades. Galileo sponsored Season 2, including episode 41; the episode has no separate sponsor read in its transcript.
K-means has known weak spots. You must choose k up front, and different starting centers can produce different groups, so tools run it several times and keep the best result. It assumes roughly round, similar-sized groups and struggles with long, thin or uneven ones. Columns on bigger scales dominate the distance, so features usually need scaling first. The groups it finds are not proof of real categories; check that they are useful. Despite the similar name, k-nearest neighbors is a different method that predicts labels from labeled examples.
Sources
- scikit-learn: Clustering, K-means — Describes Lloyd's algorithm (choose initial centroids, assign samples to the nearest centroid, recompute centroids as means, repeat), its need for a specified number of clusters, its assumption of convex, isotropic clusters and its dependence on initialization; checked October 24, 2026.
Go deeper
- scikit-learn: Selecting the number of clusters with silhouette analysis on KMeans clustering docs
Compare several values of k and see how silhouette scores reflect how well separated the resulting groups are.