How do you derive PCA as finding the direction of maximum variance?

Unsupervised learning, Principal component analysis
Level L3 Intermediate. Length Long. Nature Mat Mathematical.

What's being asked

Whether you can set up a constrained optimisation with a Lagrange multiplier and recognise an eigenvalue problem.

Key idea

Maximise u⊤Su subject to u⊤u=1, where u is the direction and S is the covariance matrix of the centred data. The Lagrangian gives Su=λu, and the variance captured is λ, so take the eigenvector with the largest eigenvalue.

Steps

  1. Centre the data (subtract the mean) and define S=1n∑ixixi⊤.
  2. The variance of the projections onto a unit vector u is u⊤Su.
  3. Form L=u⊤Su−λ(u⊤u−1), where λ is the Lagrange multiplier. Set its gradient to zero to get Su=λu.
  4. Then u⊤Su=λ, so choose the eigenvector with the largest eigenvalue.
  5. For k components, repeat with orthogonality constraints (or use the SVD of the data matrix X). Mention the equivalent view that PCA minimises the reconstruction error.

Common mistakes

How long your answer should be

About 5 minutes; half a page.

Last checked on 4 December 2026.

Read this

Previous in Unsupervised learning: Six points on a line are 1, 2, 3, 10, 11 and 12. Using a flat kernel of radius 2.5 (all points within distance 2.5 get equal weight), run mean shift by hand from the starting positions x=4 and x=9. Where does each run stop, and what do you learn about the number of clusters?
Next in Unsupervised learning: A data matrix X has one feature per column. Its covariance matrix decomposes as C=UΛU⊤ with U=12[11−11] and Λ=diag⁡(99,1). (a) What is the shape of X? (b) What steps compute C from X, and what is C explicitly? (c) To what dimension would you reduce the data with PCA, onto which direction, and why?