Lesson 6.3 · 11 min read · about 1 h to master at a very slow pace
Updating Centroids and Convergence
The update step, why K-means always converges but only to a local optimum, the effect of a bad start, choosing K with the elbow method, and the main ways K-means goes wrong.
The update step, continued
From 6.2: , . Move each centroid to its cluster mean:
Iteration 2: reassign. Every point is still closest to the same centroid, so assignments don't change: converged.
.
Why it converges
- The assignment step can't increase : each point moves to a closer (or equally close) centre.
- The update step can't increase : the mean minimises the sum of squared distances within a cluster.
- There are finitely many ways to assign points, so can't keep decreasing forever.
But it converges to a local minimum, which depends on the starting centroids.
Worked example: a poor start that recovers
1-D points ; ; start at , .
- Assign: 1 → ; 2, 4, 11, 12, 14 → . Update: , .
- Assign: 1, 2 (1 vs 6.6), 4 (3 vs 4.6) → ; 11, 12, 14 → . Update: , .
- Assign: no change. Converged. .
Here a bad start still found the natural groups. On other data it can get stuck in a poor solution, so K-means is run several times from different starts and the run with the lowest is kept. k-means++ chooses spread-out starting centroids to make bad starts rarer.
Click through the same example, one assign or update at a time:
Choosing K in K-means
always decreases as grows (with , every point is its own cluster and ), so you can't choose by minimising , just as training error can't choose model complexity.
- Elbow method: plot against and choose the bend where extra clusters stop helping much.
- Silhouette score: for each point, , where is the mean distance to its own cluster and to the nearest other cluster. Higher average is better.
- Usefulness and stability: are the clusters actionable, and do they stay similar on resampled data?
When K-means goes wrong
| Issue | Why | What to do |
|---|---|---|
| Features on different scales | Large-scale variable dominates distance | Standardise first |
| Sensitive to initialisation | Only a local optimum | Many restarts; k-means++; keep lowest |
| must be chosen | Not learned | Elbow, silhouette, domain use |
| Assumes round, similar-sized clusters | Euclidean distance to a mean | Other methods (mixtures, density-based) for elongated or nested clusters |
| Outliers | Means are pulled by extremes | Handle outliers; consider k-medians |
| Hard assignments only | Each point fully in one cluster | Soft clustering (mixture models) |
Cheatsheet
Choosing K
K-means failure modes
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.