For a clustering of data points x1,…,xN into clusters C1,…,CK with centroids μk and overall mean μ, prove that total scatter = within-cluster scatter + between-cluster scatter. Why does this show that minimising k-means cost is the same as maximising between-cluster scatter? How do you check it on the 1-D clusters {1,2} and {6,7}?

Unsupervised learning, k-means theory
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can split the total sum of squares by adding and subtracting the cluster centroid, and use the result to interpret the k-means objective.

Key idea

∑i∥xi−μ∥2=∑k∑x∈Ck∥x−μk∥2+∑kNk∥μk−μ∥2. The left side does not depend on the clustering, so lowering the first term on the right forces the second to rise.

Steps

  1. Define total scatter T=∑i∥xi−μ∥2, within-cluster scatter W=∑k∑x∈Ck∥x−μk∥2, and between-cluster scatter B=∑kNk∥μk−μ∥2, where Nk=∣Ck∣.
  2. For x∈Ck, write x−μ=(x−μk)+(μk−μ) and expand the square: ∥x−μ∥2=∥x−μk∥2+2(x−μk)⊤(μk−μ)+∥μk−μ∥2.
  3. Sum over x∈Ck. Since μk is the mean of the cluster, ∑x∈Ck(x−μk)=0, so the cross term vanishes. What remains is ∑x∈Ck∥x−μk∥2+Nk∥μk−μ∥2.
  4. Sum over k to get T=W+B.
  5. The k-means cost is W. The data fix T, so minimising W is the same as maximising B=T−W. So k-means makes clusters tight and also pushes the centroids apart.
  6. Check on {1,2},{6,7}. Overall mean μ=4, so T=9+4+4+9=26. Cluster means are 1.5 and 6.5, so W=4×0.25=1. Then B=2(2.5)2+2(2.5)2=25. Indeed 1+25=26.

Common mistakes

How long your answer should be

Half a page; 3–4 minutes.

Last checked on 4 December 2026.

Read this

Previous in Unsupervised learning: For A=(3045), find the singular values, the best rank-1 approximation A1 in the Frobenius norm, and the approximation error. What fraction of the squared Frobenius norm does A1 keep, and why is this the best possible rank-1 choice?
Next in Unsupervised learning: Centred 2-D data has covariance Σ=(5335). What is a whitening matrix W so that z=Wx has identity covariance? What is z for x=(2,0)⊤, and how do you check that ∥z∥2 equals the Mahalanobis distance of x?