How can the k-means objective be written as a trace problem over cluster indicator vectors, and what lower bound on the optimal SSE do you get by relaxing it to orthonormal matrices when the data are centred?

Unsupervised learning, k-means theory
Level L5 Expert. Length Long. Nature Mat Mathematical.

What's being asked

Whether you can rewrite SSE with normalised indicator vectors, relax the discrete constraint, and connect the result to PCA.

Key idea

For X∈Rn×d (rows are points) and normalised indicators hj=1Cj/nj, forming H=[h1,…,hk] with H⊤H=I, we have SSE=tr(XX⊤)−tr(H⊤XX⊤H). Minimising SSE is maximising tr(H⊤KH) with K=XX⊤.

Steps

  1. For a cluster, ∑i∈Cj∥xi−μj∥2=∑i∈Cj∥xi∥2−nj∥μj∥2, because the cross term sums to −2nj∥μj∥2 and the last term adds nj∥μj∥2.
  2. Write nj∥μj∥2=1nj∥∑i∈Cjxi∥2=1nj1Cj⊤XX⊤1Cj=hj⊤Khj.
  3. Sum over clusters: SSE=∑i∥xi∥2−∑jhj⊤Khj=tr(K)−tr(H⊤KH). In the discrete problem each row of H (one point) has exactly one nonzero entry, 1/nj in the column of its cluster.
  4. Relax: drop the discreteness and allow any H with H⊤H=I. By the Ky Fan theorem, max⁡tr(H⊤KH) is the sum of the top k eigenvalues of K, attained by the top k eigenvectors.
  5. Use centring: if X is centred, then K1=XX⊤1=0. Every genuine H has ∑jnj hj=1, so its column space contains 1, which contributes 0 to the trace. Hence tr(H⊤KH)≤λ1+⋯+λk−1, where λ1≥λ2≥… are the eigenvalues of X⊤X.
  6. Therefore SSE⋆≥∑j≥kλj, the variance left in the discarded directions of a (k−1)-dimensional PCA. Example: if the eigenvalues of X⊤X are 40 and 10 and k=2, then SSE⋆≥10.
  7. So the cluster indicators lie near the top k−1 principal subspace, which is why k-means is often run after PCA, and the relaxation is the same idea as in spectral clustering.

Common mistakes

How long your answer should be

One page; 8–10 minutes.

Last checked on 4 December 2026.

Read this

Previous in Unsupervised learning: For symmetric t-SNE with high-dimensional affinities pij (symmetric, with ∑i≠jpij=1) and low-dimensional affinities qij=(1+∥yi−yj∥2)−1∑k≠l(1+∥yk−yl∥2)−1, how do you derive ∂C∂yi=4∑j(pij−qij)(yi−yj)(1+∥yi−yj∥2)−1 for C=KL(P∥Q)? What do the two terms mean, and why does the Student-t kernel help with the crowding problem?
Next in Unsupervised learning: For a similarity graph with weights W, degrees D and Laplacian L=D−W, how do you derive the relaxation of the two-way normalised cut Ncut(A,B)=cut(A,B)(1vol(A)+1vol(B)) into the generalised eigenproblem Lf=λDf? How do you check the bound on the graph with w12=w34=1, w23=0.1?