Log inStart free
LESSON 4.30 · 6 STAGES · 2 CONTROLS · 3 CHECKSPRO · PREVIEW

K-means and k-means++

Watch centroids move until no point changes cluster, then try a smarter start.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 2 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 4.30 · CLUSTER BAYK = 3 · START: POINTS 26, 1, 22
01
Stage 1 of 6 · Random start
K-means sorts unlabeled points into k = 3 clusters. A random start makes 3 points the centroids.
Explain it simply

You see 40 points with no labels: a ring around a dense blob, a looser blob and 6 lone points. K-means will sort them into 3 groups. To start, it picks 3 points at random: points 26, 1 and 22. Each ochre marker on them is a centroid, the center of one group.

Forty hollow teal points: a ring around a dense blob, a looser blob and 6 lone points. The random start puts 3 ochre centroids on points 26, 1 and 22.

points, hollow before they join a clustercentroids μ and their trailsclusters (a shape each), regions, k-means++ chancesinertia J and squared distances
points and centroids024681002468x₁x₂113222426282940μAμBμCpoints and centroids024681002468x₁x₂113222426282940μAμBμC
Toy: the 4.C3 points, 40 unlabeled (a ring, two blobs, 6 lone points) · k = 2 to 4 · seeded starts
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
μj=xij,ij∼uniform{1,…,40}\sy{mu}{param}{\mu_j} = \sy{x}{data}{x_{i_j}},\quad i_j \sim \mathrm{uniform}\{1, \dots, 40\}
μA=x26=(4.1, 4.8), μB=x1=(0.8, 0.4), μC=x22=(3.8, 3.0)\mu_{\mathrm{A}} = x_{26} = (4.1,\ 4.8),\ \mu_{\mathrm{B}} = x_{1} = (0.8,\ 0.4),\ \mu_{\mathrm{C}} = x_{22} = (3.8,\ 3.0)

Each start centroid sits on a point drawn at random.

Common mix-ups

MYTHK-means always finds the best clusters.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01Seed 2 puts all three start centroids on the ring. Does k-means get stuck?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 2 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.