🧮 Brain Teaser

The PCA Variance You're Not Capturing

You run PCA on a data matrix XRn×pX \in \mathbb{R}^{n \times p} (centered, n>pn > p) and keep only the top k<pk < p principal components, obtaining a rank-kk approximation X^\hat{X}.

The reconstruction error is measured by: XX^F2\|X - \hat{X}\|_F^2

Question: Show that this equals the sum of the discarded eigenvalues of the sample covariance matrix S=1nXTXS = \frac{1}{n} X^T X. That is, if λ1λ2λp0\lambda_1 \geq \lambda_2 \geq \cdots \geq \lambda_p \geq 0 are the eigenvalues of SS, then: XX^F2=nj=k+1pλj\|X - \hat{X}\|_F^2 = n \sum_{j=k+1}^{p} \lambda_j

Bonus: What does this tell you about the optimal rank-kk approximation to XX?

PCASVDFrobenius normEckart-Youngdimensionality reductioncovariance matrix

Answer: PCA Reconstruction Error and Discarded Eigenvalues

Key Idea / Intuition

The Frobenius norm of a matrix is just the sum of squared singular values, and singular values of XX are directly related to eigenvalues of XTXX^T X. PCA throws away the directions corresponding to the smallest singular values, so the reconstruction error is precisely the total "energy" in those discarded directions. This is also the content of the Eckart–Young theorem: PCA gives the best possible rank-kk approximation in Frobenius norm.


Formal Proof / Solution

Setup via SVD. Write the thin SVD of the centered matrix: X=UΣVTX = U \Sigma V^T where URn×pU \in \mathbb{R}^{n \times p} has orthonormal columns, Σ=diag(σ1,,σp)\Sigma = \mathrm{diag}(\sigma_1, \ldots, \sigma_p) with σ1σp0\sigma_1 \geq \cdots \geq \sigma_p \geq 0, and VRp×pV \in \mathbb{R}^{p \times p} is orthogonal.

Relating singular values to covariance eigenvalues. The sample covariance is: S=1nXTX=1nVΣ2VTS = \frac{1}{n} X^T X = \frac{1}{n} V \Sigma^2 V^T So the eigenvalues of SS are λj=σj2/n\lambda_j = \sigma_j^2 / n, i.e., σj2=nλj\sigma_j^2 = n\lambda_j.

The rank-kk PCA approximation. Keeping the top kk principal components means: X^=UkΣkVkT\hat{X} = U_k \Sigma_k V_k^T where the subscript kk denotes the first kk columns/rows. This is exactly the best rank-kk approximation by the Eckart–Young theorem.

Computing the reconstruction error. The error matrix is: XX^=j=k+1pσjujvjTX - \hat{X} = \sum_{j=k+1}^{p} \sigma_j u_j v_j^T

Taking the Frobenius norm and using orthonormality of uj,vju_j, v_j: XX^F2=j=k+1pσjujvjTF2=j=k+1pσj2\|X - \hat{X}\|_F^2 = \left\|\sum_{j=k+1}^{p} \sigma_j u_j v_j^T\right\|_F^2 = \sum_{j=k+1}^{p} \sigma_j^2

since uiviTF=1\|u_i v_i^T\|_F = 1 and cross terms vanish by orthogonality. Substituting σj2=nλj\sigma_j^2 = n\lambda_j:

XX^F2=nj=k+1pλj\boxed{\|X - \hat{X}\|_F^2 = n \sum_{j=k+1}^{p} \lambda_j}

Bonus — Optimality. The Eckart–Young theorem states that among all rank-kk matrices BB: X^=argminrank(B)kXBF2\hat{X} = \arg\min_{\mathrm{rank}(B) \leq k} \|X - B\|_F^2

So PCA doesn't just minimize reconstruction error in some heuristic sense—it is provably the optimal rank-kk approximation. The proportion of variance retained is: j=1kλjj=1pλj\frac{\sum_{j=1}^k \lambda_j}{\sum_{j=1}^p \lambda_j} which is exactly the "explained variance ratio" reported by every PCA implementation. The reconstruction error formula makes this precise: you're losing exactly the variance in the dropped directions, nothing more and nothing less.

Source: The Elements of Statistical Learning, Ch. 3 & 14; standard linear algebra / ML folklore

Type: ML/StatsSource: The Elements of Statistical Learning, Ch. 3 & 14; standard linear algebra / ML folkloreEdit on GitHub ↗