Explained variance and whitening
Quick answer
Explained variance measures how much training variation a principal component captures. Whitening rescales retained scores to unit sample variance, changing their relative influence. Static examples tested locally with Python 3.13.5, scikit-learn 1.8.0 SciPy 1.17.0 and NumPy 2.3.5 where imported. ByteMind package execution is unverified.
Calculate cumulative retained variance
v=[9,4,1]print(round(sum(v[:2])/sum(v),6))print(6/(v[0]**0.5))Observed local output:
0.9285712.0Normalize by the full spectrum and divide scores by standard deviation.
How it works
For n > 1 training observations, eigenvalue λ_j = s_j²/(n−1) is the sample variance of score j. Explained variance ratio r_j = λ_j / sum of all eigenvalues, not just retained ones. For spectrum [9,4,1], keeping two directions retains 13/14 ≈ 92.86% of training variance. A cumulative threshold is a useful compression heuristic, not evidence of downstream prediction quality. Select k within validation if prediction is the goal. The whitened coordinate is z_j / sqrt(λ_j) for positive λ_j. On training rows the resulting sample covariance is the identity when the retained components have positive variance. Reconstruction reverses the scaling before adding the mean. Example: a score of 6 with eigenvalue 9 whitens to 2. Zero or tiny eigenvalues make whitening undefined or unstable in the mathematical formula; remove degenerate directions or use a justified tolerance. Whitening is not a guarantee of statistical independence or Gaussianity. It downweights dominant directions and may amplify low-variance noise; validation is essential. Ratios are dimensionless, while eigenvalues depend on feature units. Held-out reconstruction error can differ from training explained variance.
Check sample covariance after whitening
import numpy as npfrom sklearn.decomposition import PCAX=np.array([[-3,-1],[-3,1],[3,-1],[3,1]],dtype=float)p=PCA(n_components=2,whiten=True,svd_solver="full")Z=p.fit_transform(X)print(np.allclose(np.cov(Z,rowvar=False),np.eye(2)))print(np.allclose(p.inverse_transform(Z),X))Observed local output:
TrueTruePositive retained variances permit whitening and inverse scaling.
Common mistakes
Do not divide by the sum of retained eigenvalues, assume test covariance is identity, or confuse variance with standard deviation. Do not use whitening as a substitute for assessing scale or signal.
Practice and next steps
For eigenvalues 16, 4, 0, compute cumulative ratio after one and two components. Whiten a score of 8 along the first direction and explain why the third direction cannot be whitened by the formula. Complete the knowledge check and staged exercise. Next: Truncated SVD.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Explained variance and whitening — knowledge check
Apply explained variance and whitening to new scenarios.
What is the denominator of a component variance ratio?
What is the cumulative ratio for [9,4,1] with k=2?
What divides the score during whitening?
What does zero variance imply for mathematical whitening?
Does 95% explained variance guarantee 95% accuracy?