K-Means Clustering
How Lloyd's algorithm discovers groups in unlabelled data through a two-step dance of assigning points and moving centroids.
In unsupervised learning, data arrives without labels. We only have coordinates. The goal is to discover the natural groupings hidden in the geometry of the data.
Step 1: Assign
We begin by guessing where the centres might be, dropping random centroids into the space. Every point is then coloured according to whichever centroid is closest to it.
Step 2: Move
The initial guess was wrong. To improve it, we calculate the exact geometric centre (the mean) of each newly formed cluster. The centroids are moved to these new coordinates.
Convergence
We repeat the two steps: assign points to the nearest centroid, then move the centroid to the mean. The dance stops when moving the centroids no longer causes any point to change its assignment.
Where It Breaks
Because K-means measures distance straight from a centre point, it inherently assumes clusters are spherical. If the true groups form rings, moons, or irregular densities, K-means will draw a straight line right through them.
The Quick Version
- No labels: Discovering structure using only position.
- Assign: Points belong to their closest centroid.
- Move: Centroids shift to the mathematical average.
- Converge: The loop ends when assignments stabilise.
- Failure: Breaks entirely on non-spherical shapes.