Chapter 1: Classical ML

Clustering: k-means, restarts and k-means++

You will run k-means by hand, see why it can stop stuck, and pick better starts with k-means++. Interviewers ask about all three.

15 minInteractive lessonChapter 1: Classical MLLesson 27 of 30

What you will learn

  • Run Lloyd's algorithm and explain why restarts matter
  • Explain k-means++ seeding

Key terms

centroid
the mean of the points in one group
WCSS
total squared distance from each point to its group's centroid
Lloyd's algorithm
repeat: each point joins its nearest centre, then each centre moves to its group's mean
k-means++
a way to pick starting centres that sit far apart

Prerequisites

Take Explaining a model: permutation importance and SHAP first. It comes right before this lesson in the course.

Where this lesson picks up: So far every row had a label to predict. Now the rows have no labels. How can you still sort them into groups?

What comes next

k-means gives each point to exactly one group. Next: what if the groups overlap?

Next lesson: Gaussian mixtures, EM and the silhouette

More lessons in this part

Take the lesson

Short cards, one idea at a time, with quick checks as you go.