- Variance along a direction. Let w be a unit vector (length 1). Projecting every centered sample x onto w gives the score z = x·w. The variance of those scores is zᵀz/(n − 1) = (Xw)ᵀ(Xw)/(n − 1) = wᵀCw. One small product gives the spread in any direction you like.
- Maximize it under a constraint. We want the w that maximizes wᵀCw subject to wᵀw = 1. At the optimum the gradient of the objective (2Cw) is parallel to the gradient of the constraint (2w), so 2Cw = λ·2w, which is Cw = λw: w must be an eigenvector of C.
- Which eigenvector? Plug the eigenvector back in: variance = wᵀCw = wᵀ(λw) = λ·wᵀw = λ. The variance along an eigenvector equals its eigenvalue, so the largest eigenvalue gives the direction of largest spread. The trace equals the sum of the eigenvalues, so the total variance is Σλᵢ.
- Explained variance. Component k explains the fraction λₖ/Σλᵢ. Dropping components k+1…d loses exactly the sum of the dropped eigenvalues — which is the reconstruction error in squared units.
Worked example 1 — the lesson's C = [[2, 1], [1, 2]]
trace = 4, det = 2·2 − 1·1 = 3
λ = (4 ± √(4² − 4·3))/2 = (4 ± 2)/2 → 3 and 1
PC1 = [1, 1]/√2 = [0.707, 0.707] explains 3/(3+1) = 75%
PC2 = [1, −1]/√2 explains 25%
keep PC1: z = 0.707·x₁ + 0.707·x₂, and 25% of the spread is gone.
Worked example 2 — a second matrix, C = [[5, 4], [4, 5]]
trace = 10, det = 25 − 16 = 9
λ = (10 ± √(10² − 4·9))/2 = (10 ± 8)/2 → 9 and 1
explained: 9/10 = 90% and 1/10 = 10%
PC1 = [0.707, 0.707], PC2 = [0.707, −0.707]
numeric check that PC1 really is the max:
w = [1, 0] → wᵀCw = 5
w = [0.6, 0.8] → 5(0.36) + 8(0.48) + 5(0.64) = 8.84 < 9
w = PC1 → 9 exactly. Any unit w gives at most 9.
project the point x = [2, 1]:
z = 0.707·2 + 0.707·1 = 2.121
rebuild: z·PC1 = [1.500, 1.500]
residual: x − x̂ = [0.500, −0.500], squared length = 0.5
dropped fraction for this point: 0.5 / ‖x‖² = 0.5/5 = 10% ✓
The last line is the whole promise in one number: for this point and this covariance, keeping the single best direction loses exactly the 10% that PC2 accounted for — and no other direction could lose less.