k-means, properly

The oldest workhorse of clustering, taken apart. What it minimises, a proof that it can never make things worse, why it still gets stuck, how k-means++ seeding helps, how to choose k, and where the method's hidden assumptions break.

45 min

After this lesson you can

  • Write the k-means objective and say what each symbol means
  • Prove that neither the assignment step nor the update step can increase the objective, and that the loop terminates
  • Explain why the result depends on the starting centroids, and implement k-means++ seeding
  • Compute the elbow curve and the silhouette score, and say what each can and cannot tell you
  • Predict when k-means will fail (elongated or unequal clusters, unscaled features)

In this lesson

  1. What k-means is trying to do
  2. Lloyd’s algorithm, and why it can’t make things worse
  3. Stuck in bad places, and how seeding helps
  4. In code
  5. Choosing K
  6. Where k-means breaks

This lesson is part of Descent Pro

Descent Pro unlocks every lesson on the route, from base camp to the summit. Every plan starts with a free trial.

Descent Pro

Start your free trial to keep reading

This lesson, and every other lesson on the route, is part of Descent Pro. Every plan starts with a free trial, and students with a .edu email get longer. Cancel before the trial ends and you pay nothing.