k-Means++
Smart seeding that makes clustering start in the right place.
š”Core Concept
Plain k-Means picks its starting centroids at random ā and a bad draw can trap it in a poor
clustering forever. k-Means++ fixes this by choosing initial centers that are
spread out: each new seed is picked with probability proportional to its squared
distance from the nearest existing center. Better start ā faster convergence and provably better
final clusters.
š§©Key Components
Seed 1 (random)
The very first center is picked uniformly at random from the data points.D(x) distances
For each point, measure squared distance to its nearest already-chosen center.Weighted sampling
Sample the next center with probability ā D(x)² ā far-away points are favored.Then run k-Means
Once k seeds are chosen, standard Lloyd's iterations refine them to convergence.āļøHow It Works
- Choose the first center cā uniformly at random from all data points.
- For every point x, compute D(x) = distance to the closest center chosen so far.
- Pick the next center by sampling x with probability proportional to D(x)².
- Repeat steps 2ā3 until all k centers are selected.
- Run standard k-Means (assign ā update) until centroids stop moving.
P(x) = D(x)² / Σ D(x')²
šReal-World Applications
Customer segmentation
Image color quantization
Document / topic grouping
Anomaly pre-clustering
Default init in scikit-learn
ā Checkpoint Questions
- Why does random initialization sometimes leave plain k-Means stuck in a bad clustering, and how does k-Means++ reduce that risk?
- In the seeding step, why do we sample the next center with probability proportional to D(x)² rather than uniformly?
- k-Means++ spends extra time choosing seeds. Why does it usually end up faster overall than random init?