2.5.3 · D1Unsupervised Learning

Foundations — K-Means++ initialization

1,908 words9 min readBack to topic

This page assumes you have seen nothing. We build every symbol the parent note throws at you, one brick at a time, so that when you meet you already own every letter in it.


1. A data point — the dot on the page

The picture: each point is a single dot. If we measured two numbers per thing (say height and weight), the dot lives on a flat sheet of paper — two axes, one dot.

Figure — K-Means++ initialization

Why the topic needs it: K-Means++ chooses points to become centers, so first we must be able to name each candidate. are the dots we choose from.


2. The dimension and the space

  • : dots on a line.
  • : dots on paper (what our figures show).
  • : dots floating in a room.
  • : can't draw it, but the maths is identical — a list of 100 numbers per dot.

Why the topic needs it: the parent writes in . That just means " dots, each a list of numbers." Nothing scary — it's the paper the dots live on.


3. The dataset and its size

The picture: a scatter of dots, some clumped into groups. Those visible clumps are what we hope to discover.

Why the topic needs it: every sum in the parent runs "over all of " — over every one of the dots. Know that = count of dots and the sums stop being mysterious.


4. Distance — how far apart two dots are

This is the heart. Before probabilities, we need a ruler.

Why this tool and not another? We could measure distance many ways (city-block, angles, ...). We pick straight-line distance because K-Means measures how "tight" a cluster is by straight-line spread, and the initializer must speak the same language as the algorithm it feeds.

The picture — it is just Pythagoras. Put two dots on paper. The horizontal gap and the vertical gap form the two short sides of a right triangle; the distance is the long side (hypotenuse).

Figure — K-Means++ initialization

All cases covered:

  • If the two dots are the same point, both gaps are , so distance . A dot is distance zero from itself.
  • Distance is never negative — squaring kills any minus sign, and returns the non-negative root.
  • In the same idea extends: add up the squared gap in every one of the coordinates, then square-root.

5. Squared distance — and why we square

Why square instead of using plain distance? Three honest reasons:

  1. Same currency as K-Means. K-Means scores a clustering by adding up squared distances (its "cost"). The initializer measures in the same coin, so its choices directly attack the final cost.
  2. It exaggerates far points. A point twice as far has times the score. This aggressive tilt is exactly the spreading behaviour we want.
  3. No wasted square-root. Dropping is faster and, since we only compare and weight, never changes which point wins.
Figure — K-Means++ initialization
Recall Why not just

instead of ? Because pushes far points harder (2× far → 4× weight), matches K-Means' own squared-distance cost, and is what earns the theoretical guarantee. ::: correct


6. The centroid and the "min over "

So the parent's key quantity in plain words is: "the distance from dot to its nearest already-chosen center."

The picture: draw arrows from one point to all current centers; keeps the shortest arrow.

Figure — K-Means++ initialization

Why the topic needs "nearest": a point is "already covered" if any center is close. We only want to reward points that are far from everything, so we measure the gap to the closest center — if even the closest is far, the point is genuinely uncovered.


7. The sum and the total potential

Why the topic needs it: is the number we divide by so the weights turn into probabilities that add to (next section).


8. Probability , proportional-to , and the weighted dice

Putting the pieces together, the parent's headline formula now reads entirely in plain words:

the chance of picking dot next = (its squared distance to the nearest center) divided by (that same total for everybody).

Why divide by ? Dividing each weight by the grand total forces the chances to add up to exactly — the law every set of probabilities must obey — while keeping each one proportional to . That's the "weighted dice": far points get a bigger slice of the line.


Prerequisite map

data point x_i

space R^d

dataset X and count n

Euclidean distance

squared distance D squared

nearest center min over C

potential Phi = sum of D squared

probability P proportional to D squared

K-Means++ initialization

Every arrow means "you must own the box on the left before the box on the right makes sense." The whole chain ends at the parent topic, K-Means++ initialization.


Where these lead next

  • Once seeds are placed, the full clustering loop and its cost live under Expectation-Maximization (EM) (K-Means is a special case).
  • Choosing itself: Elbow Method and Silhouette Score.
  • Cousins that pick real points as centers or avoid centroids entirely: K-Medoids (PAM), Hierarchical Clustering, DBSCAN.
  • The squared-distance weighting interacts delicately with Outlier Detection, and reproducibility needs Random Seed Setting. Runtime cost sits in Computational Complexity.
  • Prefer Hinglish? See 2.5.03 K-Means++ initialization (Hinglish).

Equipment checklist

Test yourself — say the answer aloud, then reveal.

What does the subscript in mean?
It is the ID number of the point — "point number ", nothing more.
What does describe?
A dot made of ordinary numbers; is how many measurements per dot.
What do the curly braces in mean, and what is ?
"The collection of"; is the total number of dots.
Write in words for 2D.
Straight-line (Pythagoras) distance: square the x-gap, square the y-gap, add, square-root.
What is the distance from a point to itself?
Zero — all coordinate gaps are .
Why square the distance instead of using it raw?
To match K-Means' squared-distance cost, exaggerate far points (2× far → 4× weight), and earn the theoretical guarantee.
What does compute?
The distance from to its nearest already-chosen center.
What does measure?
How poorly the current centers cover all points — larger means more dots still far away.
Why divide each by ?
So the weights become probabilities that sum to exactly , while staying proportional to .
If and (only two points), what is ?
.