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?

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 U are the eigenvectors of C (the principal directions) and the diagonal of Λ holds the eigenvalues (the variance along each direction). C is 2×2, so there are 2 features and X is n×2. The first eigenvalue explains 9999+1=99% of the variance, so keep one component, the first column of U: u1=12(1,−1)⊤.

Steps

  1. (a) A covariance matrix is d×d for d features, so d=2. Features are columns, so X∈Rn×2, where n is the number of samples.
  2. (b) Compute the column means μ=1nX⊤1, where 1 is a column of n ones. Centre the data, Xc=X−1μ⊤, because covariance measures spread around the mean. Then C=1n−1Xc⊤Xc (some texts use 1n). Finally, find its eigenvalues and eigenvectors, sorted from largest eigenvalue down.
  3. Compute C explicitly. The columns of U are u1=12(1,−1)⊤ and u2=12(1,1)⊤, so C=99 u1u1⊤+1 u2u2⊤=992[1−1−11]+12[1111]=[50−49−4950].
  4. Check the result. Each feature has variance 50, and the correlation is −49/50=−0.98, so the two features move strongly in opposite directions. The trace is 50+50=100=99+1, the sum of the eigenvalues, as it must be.
  5. (c) The fraction of variance on the first component is λ1λ1+λ2=99100=99%. So reduce to 1 dimension, projecting each point onto u1: z=u1⊤(x−μ)=(x1−μ1)−(x2−μ2)2. Dropping the second component loses only 1% of the variance.

Common mistakes

How long your answer should be

Half a page; about 4 minutes.

Read this

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 μ=(0,0) and covariance Σ=[10.90.91]. What is the squared Mahalanobis distance of x1=(1,1) and of x2=(1,−1), which is anomalous at the 1% level, and would a model that treats the two features as independent Gaussians notice the difference?