Data Xn∈RD (D = original dimension; the lecture writes m), n=1..N; target dimension M (lecture: d), M<D. Sample mean Xˉ=N1∑Xn. Covariance S=N1∑n(Xn−Xˉ)(Xn−Xˉ)T (symmetric, positive semidefinite). Eigen-pairs Sui=λiui, λ1≥⋯≥λD≥0.
Errata in the lecture notes (corrected here)
(1) The projection is Z′=ZE with E=[E1..Ed] of size m×d (the printed ZET has mismatched dimensions). (2) “Eigenvectors corresponding to the least (d−m) eigenvalues” should read the least (m−d) eigenvalues. (3) Linear independence means ∑βjOj=0⇒allβj=0 (the printed "∀βj=0" is garbled).
Python helper — run once, the checks below reuse it
import numpy as npnp.set_printoptions(precision=4, suppress=True)def pca(X, bias=True): """Eigenvalues (descending), eigenvectors (columns), centred data Z, covariance S. bias=True divides by N, as in these notes (sklearn divides by N-1). Eigenvector signs are arbitrary.""" X = np.asarray(X, float); Z = X - X.mean(0) S = Z.T @ Z / (len(X) if bias else len(X) - 1) w, V = np.linalg.eigh(S); i = np.argsort(w)[::-1] return w[i], V[:, i], Z, S
flowchart LR
X["Data X (N×D)"] --> C["centre: Z = X − mean"]
C --> S["covariance S = ZᵀZ / N"]
S --> E["eigen-decompose<br/>keep top-M eigenvectors E"]
E --> P["scores Z' = Z E (N×M)"]
P --> R["reconstruct: mean + Z' Eᵀ"]
C43. Orthonormal Bases, Coordinates and Projections (Prerequisite)
Intuition
Coordinates relative to a rotated set of perpendicular unit axes are just dot products. PCA is a search for the best rotated axes.
Formal definitions
A set {O1..OD} is a basis of RD if the vectors are linearly independent and every vector is a linear combination of them.
It is orthonormal if OjTOj=1 (unit length) and OjTOr=0 for r=j.
For an orthonormal basis, coordinates are dot products:
X=∑j=1D(XTOj)Oj.
Parseval:∥X∥2=∑j(XTOj)2.
Projection onto the first d axes:X^=∑j=1d(XTOj)Oj; the residual X−X^=∑j>d(XTOj)Oj is orthogonal to the subspace, and ∥X−X^∥2=∑j>d(XTOj)2.
Derivation (the expansion formula; lecture appendix)
Write X=∑rαrOr (possible since it is a basis). Take the inner product with Oj: XTOj=∑rαrOrTOj=αj, because OrTOj=0 for r=j and =1 for r=j. Hence αj=XTOj. Parseval: ∥X∥2=∑r,jαrαjOrTOj=∑jαj2. ∎
Key insights
The projection is the closest point of the subspace to X (orthogonal projection).
A rotation (orthonormal change of basis) preserves lengths and angles.
Worked examples
Example 1 — Very Easy · Is it orthonormal?
Problem: Is {O1=21(1,1),O2=21(1,−1)} orthonormal?
O = np.array([[1,2,2], [2,1,-2], [2,-2,1]]) / 3; x = np.array([3, 6, 0])a = O @ x; print(a, O @ O.T) # [ 5. 4. -2.] and the identityprint(a @ O, x @ x, a @ a) # [3. 6. 0.] 45 45
Key lesson
Lengths are preserved by orthonormal coordinates.
Example 4 — Hard · Project onto two of three axes
Problem: With the basis of Example 3, project X=(3,6,0) onto span{O1,O2}. Find the projection, the residual and its squared length. Then compare with using span{O1,O3}.
The error equals the sum of squares of the discarded coordinates — so discard the small ones.
Example 5 — Very Hard · Rotations and truncation error
Problem: Show that if Q=[O1⋯OD] has orthonormal columns then QTQ=I, QQT=I, and ∥QTX∥=∥X∥. Then show that the squared reconstruction error of an arbitrary choice of d axes from the basis, summed over a data set, equals ∑j dropped∑n(XnTOj)2.
Asked: Two proofs.
Concept: Rotation and truncation.
Approach: Matrix algebra.
Solution:(QTQ)jr=OjTOr=δjr ⇒ QTQ=I. For a square Q, QT=Q−1 ⇒ QQT=I. ∥QTX∥2=XTQQTX=∥X∥2. Truncation: for each n, residual =∑j∈dropped(XnTOj)Oj; by orthonormality its squared norm is ∑j∈dropped(XnTOj)2; sum over n. ∎
Final answer: As shown.
Key lesson
Total error splits axis by axis — the basis of the minimum-error derivation (C45).
Common mistakes
Using a non-unit vector for coordinates (αj=XTOj needs ∥Oj∥=1).
Forgetting orthogonality between axes.
Exam traps
Orthonormal ⇒ both unit and orthogonal; orthogonal alone is not enough.
Linear independence ≠ orthogonality.
Connections: C44–C45.
Mastery checklist
Verify orthonormality.
Compute coordinates and reconstruct.
State Parseval and use it for truncation error.
C44. PCA as Maximum Variance (Bishop §12.1.1)
Intuition
Squash the data onto a line (or plane) so that the spread of the squashed points is as large as possible — you keep the most “information” (spread) in the fewest dimensions. Like photographing a pencil: shoot it from the side, not end-on.
╱ ● ● PC1 = direction of greatest spread
● ● ●╱ (a tilted cloud: better than either axis)
● ● ╱
● ╱ ● ← PC2 is perpendicular, with much less spread
Formal derivation
Project onto a unit direction u1 (u1Tu1=1; only direction matters). Each Xn↦u1TXn. The mean of the projections is u1TXˉ; the variance is
N1∑n(u1TXn−u1TXˉ)2=u1TSu1.
Maximise u1TSu1 subject to u1Tu1=1. Lagrangian L=u1TSu1+λ1(1−u1Tu1). ∇L=2Su1−2λ1u1=0⇒Su1=λ1u1. So u1 is an eigenvector; left-multiplying by u1T: variance =u1TSu1=λ1. Maximum ⇒ largest eigenvalue. Further components: maximise variance among directions orthogonal to those already chosen ⇒ eigenvectors of the next-largest eigenvalues (proof by induction). The M-dimensional optimum is spanned by u1..uM and retains total variance ∑i≤Mλi.
Key insights
Scores on different PCs are uncorrelated: Cov(uiTX,ujTX)=uiTSuj=λjuiTuj=0.
Total variance =trS=∑i=1Dλi.
Cost: full eigendecomposition O(D3); first M only, via the power method, O(MD2).
Worked examples
Example 1 — Very Easy · Diagonal covariance
Problem:S=(2001). Principal components and variances?
Asked: Eigen-pairs.
Concept: Diagonal covariance.
Approach: Read off.
Solution:λ1=2,u1=(1,0); λ2=1,u2=(0,1).
Final answer: PC1 along x with variance 2.
Key lesson
Uncorrelated features ⇒ the axes are the PCs.
Example 2 — Easy · Correlated features
Problem:S=(3113). Find the PCs and compare the variance along u1 with the variance along (1,0).
Asked: Eigen-pairs and a comparison.
Concept:λ=uTSu.
Approach:det(S−λI)=0.
Solution:(3−λ)2−1=0⇒λ=4,2. λ=4: u1=21(1,1). λ=2: u2=21(1,−1). Variance along (1,0): 3<4.
Final answer:(4,21(1,1)), (2,21(1,−1)); axis-aligned variance 3.
Correlation tilts the best direction off the axes.
Example 3 — Moderate · A nearly one-dimensional cloud
Problem: Deviations of height and arm-span from the mean for four people: (−2,−1),(−1,−1),(1,1),(2,1) (mean zero). Find S, the first PC, its variance and the fraction of total variance kept.
Example 4 — Hard · Retained variance and the Rayleigh quotient
Problem:S=diag(5,3,2). (a) Variance retained by M=1,2. (b) The variance along the unit direction u=(1,1,0)/2 and why it is below λ1.
Asked: Fractions and a directional variance.
Concept: Rayleigh quotient.
Approach:uTSu.
Solution: (a) Total =10. M=1: 50%; M=2: 80%. (b) uTSu=21(5+3)=4<5. In general uTSu=∑iλi(uTui)2 is a weighted average of the eigenvalues (weights sum to 1) ⇒ ≤λ1 with equality only for u=u1.
Final answer:50%,80%; directional variance 4.
Python check
S = np.diag([5, 3, 2.]); u = np.array([1, 1, 0]) / np.sqrt(2)print(u @ S @ u, np.cumsum([5, 3, 2]) / 10) # 4.0 [0.5 0.8 1. ]
Key lesson
The Rayleigh quotient is bounded by the extreme eigenvalues.
Example 5 — Very Hard · Scores are uncorrelated
Problem: For Example 3 compute the scores on PC1 and PC2 for the four points, verify their variances equal λ1,λ2 and that the scores are uncorrelated. Also prove uncorrelatedness in general.
Asked: Numerical and general proof.
Concept: Decorrelation.
Approach: Project.
Solution:u1=(0.8507,0.5257), u2=(−0.5257,0.8507). Scores z1: −2.2271,−1.3764,1.3764,2.2271; z2: 0.2007,−0.3250,0.3250,−0.2007. Var(z1)=3.4273 ✓ =λ1; Var(z2)=0.0730 ✓. Cov≈0 ✓. General: Cov(zi,zj)=uiTSuj=λjuiTuj=0 for i=j, since eigenvectors of a symmetric matrix with different eigenvalues are orthogonal. ∎
Final answer: Variances 3.427,0.073; covariance 0.
Python check
scores = Z @ V # signs of columns may differ from the textprint(scores.var(0), np.cov(scores.T, bias=True)) # [3.4271 0.0729] diag(3.4271, 0.0729), off-diagonal 0
Key lesson
PCA produces uncorrelated coordinates — hence its other name, the Karhunen–Loève transform.
Common mistakes
Not centring (variance is about the mean).
Forgetting the unit-norm constraint (the variance could be made infinite).
Exam traps
Variance along PC i is λi; total variance is trS.
C45. PCA as Minimum Reconstruction Error (Lecture §20.4; Bishop §12.1.2)
Intuition
Instead of “keep the spread”, ask “which M-dimensional flat surface lies closest to the data on average?” Remarkably, the answer is the same subspace.
Formal derivation (lecture, step by step)
Take a complete orthonormal basis {Oj}j=1D and approximate each data point
X~n=∑j=1MαnjOj+∑j=M+1DβjOj,
with coefficients αnj depending on n but βj the same for all points. Distortion
J=N1∑n∥Xn−X~n∥2=N1∑n[∑j≤M(XnTOj−αnj)2+∑j>M(XnTOj−βj)2]
(by orthonormality). Minimising over the coefficients:
∂αnj∂J=0⇒αnj=XnTOj;∂βj∂J=0⇒βj=XˉTOj.
So X~n=∑j≤M(XnTOj)Oj+∑j>M(XˉTOj)Oj and Xn−X~n=∑j>M((Xn−Xˉ)TOj)Oj — lying in the space orthogonal to the principal subspace. Then
J=∑j=M+1DN1∑n[(Xn−Xˉ)TOj]2=∑j=M+1DOjTSOj.
Minimise subject to OjTOj=1: L=∑j>M[OjTSOj+λj(1−OjTOj)]; ∂L/∂Oj=2SOj−2λjOj=0⇒SOj=λjOj, giving OjTSOj=λj. Hence
Jmin=j=M+1∑Dλj,
attained by discarding the eigenvectors with the D−M smallest eigenvalues, i.e. keeping the M largest. (Covariance matrices are symmetric PSD, so eigenvalues are real and ≥0.)
Key insights
Max-variance and min-error give the same principal subspace (total variance =∑λ is fixed, so keeping more variance = losing less error).
The offsets βj say: in the discarded directions, replace the point’s coordinate by the mean’s coordinate.
Error curve (Bishop Fig. 12.4b): J(M)=∑j>Mλj decreases as M grows; J(D)=0.
Worked examples
Example 1 — Very Easy · Error = discarded eigenvalues
Problem: Eigenvalues (5,3,2,1). Minimum J for M=2.
Asked:J.
Concept:J=∑j>Mλj.
Approach: Sum the tail.
Solution:2+1=3.
Final answer:J=3.
Key lesson
Error = the discarded eigenvalues.
Example 2 — Easy · How many components for 90 %?
Problem: Eigenvalues (4,2.5,1.5,1,0.5,0.5). Smallest M retaining ≥90% of the variance.
The lecture notes that no principled automatic choice of M exists — thresholds like this are a heuristic.
Example 3 — Moderate · Keep the right axis
Problem: Points (1,1),(3,1),(2,4); mean (2,2). Using the (not necessarily optimal) basis O1=(1,0), O2=(0,1) and M=1, compute J if O2 is the discarded axis and if O1 is discarded.
Asked: Two distortions.
Concept: Formula for J.
Approach:J=OdiscTSOdisc.
Solution:S11=32; S22=2; S12=0. Discard O2: J=2. Discard O1: J=32. Direct check (discard O2, replace y by the mean 2): errors −1,−1,2 ⇒ 31+1+4=2 ✓.
Final answer:J=2 vs J=32.
Key lesson
Keep the high-variance axis, discard the low-variance one.
Example 4 — Hard · One direction, three choices
Problem:S=(3113), M=1. Compute J if the discarded unit direction is (a) (1,0), (b) u2=21(1,−1), (c) u1=21(1,1).
Final answer:3,2,4; the minimum 2=λ2 occurs when discarding the eigenvector of the smaller eigenvalue.
Python check
S = np.array([[3, 1], [1, 3.]])for o in ([1, 0], [1, -1], [1, 1]): o = np.array(o) / np.linalg.norm(o); print(o @ S @ o) # 3.0 2.0 4.0
Key lesson
J∈[λmin,λmax] for any one-direction discard.
Example 5 — Very Hard · Why the smallest eigenvector is optimal
Problem: Prove that if O is a unit vector then OTSO≥λmin with equality iff O is an eigenvector for λmin; deduce the PCA optimality for M=D−1 and verify with the data of C44 Ex. 3.
Asked: Proof and check.
Concept: Rayleigh quotient.
Approach: Expand in the eigenbasis.
Solution: Write O=∑iciui with ∑ci2=1. OTSO=∑iλici2≥λmin∑ci2=λmin, equality iff ci=0 whenever λi>λmin. For M=D−1 exactly one direction is discarded, so Jmin=λD, achieved by the least-variance eigenvector. Check: C44 Ex. 3 data, discarding u2: errors z22=(0.0403,0.1056,0.1056,0.0403), mean =0.0730=λ2 ✓; discarding (1,0) instead: J=S11=2.5.
Final answer:Jmin=λD; numeric check 0.073 vs 2.5 for a poor choice.
Key lesson
The reconstruction error is exactly the variance in the discarded direction.
Common mistakes
Confusing “keep the eigenvectors of the smallest eigenvalues” with discarding them.
Forgetting that βj uses the mean.
Exam traps
Jmin=∑j>Mλj (the sum of discarded eigenvalues).
If eigenvalues are equal, any basis of their eigenspace is equivalent.
Connections: C43, C44, C48 (reconstruction).
Mastery checklist
Reproduce the derivation of αnj,βj.
Derive J=∑j>Mλj.
Compute reconstruction errors.
C46. The PCA Algorithm, Standardisation and Whitening
Intuition
Centre the data, find the eigen-directions of its covariance, and express each point by its coordinates along the top ones. Optionally rescale so every direction has unit variance (whitening), or work with correlations (standardising) so units do not matter.
Algorithm (lecture, with the corrections above)
Subtract each feature’s mean: X^i=Xi−Xˉ; stack as Z (n×m).
Form the m×m covariance matrix S=n1ZTZ (the lecture uses ZTZ — same eigenvectors, eigenvalues scaled by n).
Find the d largest eigenvalues.
Take the corresponding unit eigenvectors as columns of E=[E1..Ed](m×d).
Standardising: dividing each centred feature by its standard deviation gives zero mean, unit variance; the covariance matrix then equals the correlation matrixρij=σiσjSij (ρ=1 perfect positive correlation, 0 uncorrelated).
Whitening (sphering): with S=UΛUT, define yn=Λ−1/2UT(Xn−Xˉ). Then
N1∑nynynT=Λ−1/2UTSUΛ−1/2=Λ−1/2ΛΛ−1/2=I,
zero mean and identity covariance: all variables decorrelated and unit-variance.
Key insights
PCA is scale-dependent: standardise when units differ (e.g. kilograms vs metres).
Choosing d: no good automatic method (variance threshold or the elbow of the eigenvalue spectrum).
Centring is needed for the covariance to equal n1ZTZ.
Worked examples
Example 1 — Very Easy · Centre and measure the spread
Problem: Centre the data {2,4,6} (one feature) and give the covariance.
Asked: Centred data and variance.
Concept: Steps 1–2.
Approach: Mean =4.
Solution:Z=(−2,0,2); variance =34+0+4=2.667.
Final answer:(−2,0,2); 2.667.
Key lesson
Centre first.
Example 2 — Easy · A covariance matrix
Problem: Two features with data (1,2),(3,2),(2,5). Centre and compute S.
Zero covariance ⇒ the PCs are the coordinate axes.
Example 3 — Moderate · Project, reconstruct, measure the error
Problem: Full PCA (to d=1) of the points (−2,−1),(−1,−1),(1,1),(2,1): give Z′ and the reconstruction of the first point and its error.
Asked:Z′, X~1, error.
Concept:Z′=ZE.
Approach:E=u1=(0.8507,0.5257)T.
Solution:Z′=ZE=(−2.2271,−1.3764,1.3764,2.2271)T (a 4×1 matrix). Reconstruction of X1: z1′u1=(−1.8946,−1.1708). Error vector =(−0.1054,0.1708); ∥e∥2=0.0403. Mean squared error over the four points =0.0730=λ2 ✓.
Algorithm and theory agree: MSE = the discarded eigenvalue.
Example 4 — Hard · Grams vs kilograms
Problem: Two features measured in different units: A=(100,200,300) (grams), B=(1,3,2) (kilograms). Compare the first PC on raw data and on standardised data.
Asked: Two PC1’s.
Concept: Scale dependence; correlation matrix.
Approach: Raw S, then ρ.
Solution: Means 200 and 2. SAA=6666.7; SBB=0.6667; SAB=33.33. Raw: λ1≈6666.8, u1≈(1,0.005) — essentially feature A alone (units dominate). Standardised: σA=81.65, σB=0.8165; ρ=0.5; correlation matrix (10.50.51) ⇒ λ=1.5,0.5, u1=21(1,1) — both features contribute equally.
Final answer: Raw PC1 ≈ feature A; standardised PC1 =21(1,1).
C47. PCA When N<D (High-Dimensional Data; Bishop §12.1.4)
Intuition
If you have 200 face images of 106 pixels each, the covariance is 106×106 — impossible — but the data only span an at-most-199-dimensional subspace. Solve a smallN×N eigenproblem instead and map the eigenvectors back (this is how “eigenfaces” are computed).
Formal derivation
Let X be the N×D centred data matrix (rows (Xn−Xˉ)T). Then S=N1XTX and Sui=λiui reads N1XTXui=λiui. Multiply by X and set vi=Xui:
N1XXTvi=λivi,
an eigenproblem for the N×N matrix N1XXT with the same non-zero eigenvalues. Conversely, multiply by XT: N1XTX(XTvi)=λi(XTvi), so XTvi is an eigenvector of S; normalising (∥vi∥=1):
ui=(Nλi)1/21XTvi.
Rank: N centred points span at most N−1 dimensions ⇒ at least D−N+1 eigenvalues of S are 0. Cost O(N3) instead of O(D3).
Key insights
Never form the D×D matrix when N<D.
PCA with M>N−1 is pointless.
Worked examples
Example 1 — Very Easy · Rank bound
Problem:N=3 points in D=100 dimensions. Maximum number of non-zero eigenvalues of S?
Asked: Rank bound.
Concept:rank≤N−1.
Approach: Centred points sum to zero.
Solution:N−1=2.
Final answer: At most 2 (so 98=D−N+1 eigenvalues equal 0).
Key lesson
Centring costs one dimension.
Example 2 — Easy · Counting zero eigenvalues
Problem: How many zero eigenvalues does S have for N=200, D=106?
Asked: Count.
Concept:D−N+1.
Approach: Subtract.
Solution:106−200+1=999,801.
Final answer:999,801.
Key lesson
Almost all directions carry no variance.
Example 3 — Moderate · The small eigenproblem
Problem:N=3, D=4 centred data X with rows (1,0,1,0),(−1,0,1,0),(0,0,−2,0). Find the eigenvalues of N1XXT.
Asked:λi.
Concept: Small eigenproblem.
Approach:G=XXT.
Solution:G=20−202−2−2−24. Row sums are 0 ⇒ 1 is a null vector (eigenvalue 0). Trace =8. Others: μ=2 with v=21(−1,1,0) and μ=6 with v=61(1,1,−2). Dividing by N=3: λ=(2,32,0).
Solve a 3×3 problem instead of a 4×4 one — scaling to huge D is the point.
Example 4 — Hard · Map back to the big space
Problem: For Example 3 recover the eigenvectors ui of the 4×4 covariance via ui=XTvi/Nλi and verify Su=λu.
Asked:u1,u2.
Concept: Mapping back.
Approach: Use the boxed formula.
Solution: For λ1=2 (Nλ=6), v=61(1,1,−2): XTv=61(0,0,6,0); divide by 6: u1=(0,0,1,0), unit length ✓. S=31XTX=diag(32,0,2,0) ⇒ Su1=2u1 ✓. For λ2=32 (Nλ=2), v=21(−1,1,0): XTv=21(−2,0,0,0); divide by 2: u2=(−1,0,0,0) ✓, Su2=32u2 ✓.
Final answer: PCs are the coordinate axes ±e3,±e1 with variances 2,32.
Python check
lam, Vv = np.linalg.eigh(Xn @ Xn.T / 3)for l, v in zip(lam[::-1], Vv[:, ::-1].T): if l > 1e-9: u = Xn.T @ v / np.sqrt(3 * l); print(round(l, 4), u, np.allclose(Xn.T @ Xn / 3 @ u, l * u))# 2.0 ±[0 0 1 0] True 0.6667 ±[1 0 0 0] True
Key lesson
The two-step method reproduces the direct answer.
Example 5 — Very Hard · Cost comparison
Problem: Compare costs for N=100 images, D=106 pixels, using (a) the D×D eigendecomposition, (b) the N×N route, (c) M=10 components by the power method on S. Also state how many meaningful components exist.
Asked: Operation counts and rank.
Concept: Complexity.
Approach:O(D3), O(N3), O(MD2).
Solution: (a) D3=1018. (b) N3=106 (plus forming XXT costs N2D=1010 and mapping back O(NDM)). (c) MD2=1013. Meaningful components: at most N−1=99.
Final answer:1018 vs ≈1010 vs 1013; ≤99 components.
Key lesson
The N×N trick turns an impossible computation into a trivial one.
Common mistakes
Forgetting to normalise ui (it needs the (Nλi)−1/2 factor).
Using the uncentred XXT.
Exam traps
Non-zero eigenvalues of XXT/N and XTX/N coincide.
vi=Xui is not normalised unless scaled.
Connections: C44–C46; singular value decomposition; kernel PCA.
Mastery checklist
State the rank bound.
Derive ui=XTvi/Nλi.
Compare computational costs.
C48. Applications of PCA and Comparison with Fisher’s Linear Discriminant
Intuition
PCA is used for compression, preprocessing / decorrelating, visualisation (project to 2-D) and feature extraction. It ignores class labels; Fisher’s discriminant uses them to find the direction that best separates classes.
Facts
Compression: replace Xn∈RD by M numbers (XnTui)i≤M; reconstruct Xˉ+∑i≤M((Xn−Xˉ)Tui)ui (Bishop eq. 12.19–12.20). Smaller M ⇒ higher compression, larger error J=∑i>Mλi.
Fisher’s linear discriminant (two classes, within-class scatter SW): the direction maximising J(w)=wTSWw(wT(m2−m1))2 is w∝SW−1(m2−m1).
Related: canonical correlation analysis (CCA) handles two variable sets; probabilistic PCA (Bishop §12.2) casts PCA as a latent-variable Gaussian model (maximum likelihood, EM, Bayesian choice of M) — introduced but not developed in the scanned pages.
Same data, different story once you standardise — C46 Example 4 in real life.
Worked examples
Example 1 — Very Easy · Compression ratio
Problem: Images of 28×28 pixels (D=784) are compressed to M=50 PCA scores. Compression ratio per image?
Asked: Ratio.
Concept: Compression.
Approach:D/M (ignoring the shared mean and basis).
Solution:784/50=15.7.
Final answer: About 15.7× fewer numbers per image.
Key lesson
The shared basis is amortised over the data set.
Example 2 — Easy · Error and retained variance
Problem: Eigenvalue spectrum (10,6,3,1,0.5,0.5). J and retained variance for M=2.
Asked:J, percentage.
Concept:J=∑i>Mλi.
Approach: Total =21.
Solution:J=3+1+0.5+0.5=5; retained =16/21=76.2%.
Final answer:J=5; 76.2%.
Key lesson
Each extra component adds its eigenvalue to the retained variance.
Example 3 — Moderate · A 2-D picture of 3-D data
Problem: Using the orthonormal basis of C43 (Ex. 3) as “principal axes” for the point X=(3,6,0) with M=2: give the 2-D visualisation coordinates and the reconstruction.
Final answer: Plot at (5,4); reconstruction error 4.
Key lesson
The picture shows α1,α2 only; α3 is the lost information.
Example 4 — Hard · PCA is label-blind
Problem: Two classes in 2-D with means (0,−1) and (0,1); within-class covariance SW=diag(100,1) and total covariance dominated by the x-direction (large within-class spread). Find the PCA direction and Fisher’s direction; compute Fisher’s criterion for each.
Asked: Two directions, two scores.
Concept: Unsupervised vs supervised projection.
Approach:wF∝SW−1(m2−m1).
Solution: PCA’s first direction is the largest-variance axis, wPCA=(1,0). Fisher: m2−m1=(0,2); SW−1=diag(0.01,1) ⇒ wF∝(0,1). Criterion: J(wPCA)=10002=0; J(wF)=122=4.
Final answer: PCA keeps x (class separation 0); Fisher keeps y (criterion 4).
PCA is label-blind (Bishop Fig. 12.7) — the same lesson as C3 Example 5.
Example 5 — Very Hard · PCA and whitening together
Problem: A data set has 4 PCs with eigenvalues (8,4,2,2). (a) How many components are needed for ≤10% reconstruction error? (b) After whitening all 4 components, what is the covariance and the new reconstruction error if the last two are dropped? (c) Why is whitening then PCA-truncation not equivalent to PCA-truncation?
Asked: Three answers.
Concept: Interaction of PCA and whitening.
Approach: Cumulative variance; whitened eigenvalues are all 1.
Solution: (a) Total 16; need retained ≥90%=14.4: M=3: 14 (87.5%, error 12.5%); M=4: 16. So all 4. (b) Whitened covariance =I4; dropping two components loses 2/4=50% of the (now equal) variance — error =2 (whitened units). (c) After whitening every direction has variance 1, so no direction is more important by variance; truncation then discards directions arbitrarily, not those with least original variance. Whitening is for decorrelation / normalisation, not for compression.
Final answer: (a) 4 components; (b) I4, error 2 (50%); (c) whitening removes the variance ranking.
Key lesson
Do dimensionality reduction before (or instead of) whitening.
Common mistakes
Using PCA when the class-discriminative direction has small variance.
Reporting PCA scores without keeping the mean and basis.
Exam traps
PCA: unsupervised, uses only X; Fisher: supervised, uses labels.