A data matrix has one feature per column. Its covariance matrix decomposes as with and . (a) What is the shape of ? (b) What steps compute from , and what is explicitly? (c) To what dimension would you reduce the data with PCA, onto which direction, and why?
Unsupervised learning, Dimensionality reduction
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you can read off shapes, compute a covariance matrix correctly (centring first), and use the eigenvalues to justify how many components to keep.
Key idea
The columns of are the eigenvectors of (the principal directions) and the diagonal of holds the eigenvalues (the variance along each direction). is , so there are 2 features and is . The first eigenvalue explains of the variance, so keep one component, the first column of : .
Steps
- (a) A covariance matrix is for features, so . Features are columns, so , where is the number of samples.
- (b) Compute the column means , where is a column of ones. Centre the data, , because covariance measures spread around the mean. Then (some texts use ). Finally, find its eigenvalues and eigenvectors, sorted from largest eigenvalue down.
- Compute explicitly. The columns of are and , so .
- Check the result. Each feature has variance 50, and the correlation is , so the two features move strongly in opposite directions. The trace is , the sum of the eigenvalues, as it must be.
- (c) The fraction of variance on the first component is . So reduce to 1 dimension, projecting each point onto : . Dropping the second component loses only 1% of the variance.
Common mistakes
- Writing without centring, or saying is when the question says features are columns.
- Taking the first row of as the principal direction. The eigenvectors are the columns.
- Saying 99% of the variance means 99% of the information. It only means 99% of the squared spread.
How long your answer should be
Half a page; about 4 minutes.
Read this
- Mathematics for Machine Learning (Deisenroth, Faisal, Ong): Free PDF. Section 10.2 (Maximum Variance Perspective), p. 320: the principal direction is the top eigenvector of the data covariance. Section 10.6 (Key Steps of PCA in Practice), p. 336: centre, (optionally) standardise, eigendecompose, project, with a worked 2-D example.
- An Introduction to Statistical Learning (ISLR, 2nd ed.): Free PDF. Section 12.2.3 (The Proportion of Variance Explained), p. 503: PVE = lambda_m / sum of lambdas and using it to choose how many components to keep.
- NPTEL: Deep Learning, Part 1 (IIT Ropar, Prof. Sudarshan Iyengar; lectures by Prof. Mitesh M. Khapra): Week 5: Eigenvalue Decomposition to PCA: Practical Example, which works through PCA from the covariance eigenvectors.
Previous in Unsupervised learning: How do you derive PCA as finding the direction of maximum variance?
Next in Unsupervised learning: Normal data in 2-D is modelled as a Gaussian with mean and covariance . What is the squared Mahalanobis distance of and of , which is anomalous at the 1% level, and would a model that treats the two features as independent Gaussians notice the difference?