Module 8 — Principal Component Analysis (Dimensionality Reduction)

Sources: Lec 20 — PCA for Dimensionality Reduction; Bishop, Pattern Recognition and Machine Learning, §12.1 (pp. 561–570, scanned; probabilistic PCA §12.2 only introduced there).

Notation. Data ( = original dimension; the lecture writes ), ; target dimension (lecture: ), . Sample mean . Covariance (symmetric, positive semidefinite). Eigen-pairs , .

Errata in the lecture notes (corrected here). (1) The projection is with of size (the printed has mismatched dimensions). (2) “Eigenvectors corresponding to the least eigenvalues” should read the least eigenvalues. (3) Linear independence means all (the printed "" is garbled).


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 is a basis of if the vectors are linearly independent and every vector is a linear combination of them.
  • It is orthonormal if (unit length) and for .
  • For an orthonormal basis, coordinates are dot products:
  • Parseval: .
  • Projection onto the first axes: ; the residual is orthogonal to the subspace, and .

Derivation (the expansion formula; lecture appendix)

Write (possible since it is a basis). Take the inner product with : because for and for . Hence . Parseval: . ∎

Key insights

  • The projection is the closest point of the subspace to (orthogonal projection).
  • A rotation (orthonormal change of basis) preserves lengths and angles.

Worked examples

Example 1 — Very Easy

  • Problem: Is orthonormal?
  • Asked: Check.
  • Concept: Definition.
  • Approach: Norms and dot product.
  • Solution: ; ; .
  • Final answer: Yes.
  • Key lesson: Orthonormal = unit length + mutually perpendicular.

Example 2 — Easy

  • Problem: Coordinates of in that basis; reconstruct .
  • Asked: and reconstruction.
  • Concept: .
  • Approach: Dot products.
  • Solution: ; . ✓.
  • Final answer: .
  • Key lesson: Coordinates are rotated components.

Example 3 — Moderate

  • Problem: , , . Verify orthonormality, find the coordinates of , and check Parseval.
  • Asked: Verification, , norm check.
  • Concept: Orthonormal basis in .
  • Approach: Dot products.
  • Solution: , similarly for . ; ; ✓. ; ; . Reconstruction: ✓. Parseval: ✓.
  • Final answer: .
  • Key lesson: Lengths are preserved by orthonormal coordinates.

Example 4 — Hard

  • Problem: With the basis of Example 3, project onto . Find the projection, the residual and its squared length. Then compare with using .
  • Asked: Projection and errors.
  • Concept: Truncated expansion error.
  • Approach: Drop the omitted coordinate.
  • Solution: . Residual ; ✓. Using drops : error .
  • Final answer: Error vs .
  • Key lesson: The error equals the sum of squares of the discarded coordinates — so discard the small ones.

Example 5 — Very Hard

  • Problem: Show that if has orthonormal columns then , , and . Then show that the squared reconstruction error of an arbitrary choice of axes from the basis, summed over a data set, equals .
  • Asked: Two proofs.
  • Concept: Rotation and truncation.
  • Approach: Matrix algebra.
  • Solution: ⇒ . For a square , ⇒ . . Truncation: for each , residual ; by orthonormality its squared norm is ; sum over . ∎
  • 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 ( needs ).
  • 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.

Formal derivation

Project onto a unit direction (; only direction matters). Each . The mean of projections is ; the variance is Maximise subject to . Lagrangian . . So is an eigenvector; left-multiplying by : variance . Maximum ⇒ largest eigenvalue. Further components: maximise variance among directions orthogonal to those already chosen ⇒ eigenvectors of the next-largest eigenvalues (proof by induction). The -dimensional optimum is spanned by and retains total variance .

Key insights

  • Scores on different PCs are uncorrelated: .
  • Total variance .
  • Cost: full eigendecomposition ; first only, via the power method, .

Worked examples

Example 1 — Very Easy

  • Problem: . Principal components and variances?
  • Asked: Eigen-pairs.
  • Concept: Diagonal covariance.
  • Approach: Read off.
  • Solution: ; .
  • Final answer: PC1 along with variance 2.
  • Key lesson: Uncorrelated features ⇒ axes are the PCs.

Example 2 — Easy

  • Problem: . Find the PCs and compare the variance along with the variance along .
  • Asked: Eigen-pairs and a comparison.
  • Concept: .
  • Approach: .
  • Solution: . For : . For : . Variance along : .
  • Final answer: , ; axis-aligned variance .
  • Key lesson: Correlation tilts the best direction off the axes.

Example 3 — Moderate

  • Problem: Data (mean zero). Find , the first PC, its variance and the fraction of total variance kept.
  • Asked: , fraction.
  • Concept: PCA.
  • Approach: .
  • Solution: ; ; . , . . : ; normalised . Fraction .
  • Final answer: , , of variance.
  • Key lesson: A nearly 1-D cloud compresses almost losslessly.

Example 4 — Hard

  • Problem: . (a) Variance retained by . (b) The variance along the unit direction and why it is below .
  • Asked: Fractions and a directional variance.
  • Concept: Rayleigh quotient.
  • Approach: .
  • Solution: (a) Total . : ; : . (b) . In general is a weighted average of the eigenvalues (weights sum to ) ⇒ with equality only for .
  • Final answer: ; directional variance .
  • Key lesson: The Rayleigh quotient is bounded by the extreme eigenvalues.

Example 5 — Very Hard

  • Problem: For Example 3 compute the scores on PC1 and PC2 for the four points, verify their variances equal and that the scores are uncorrelated. Also prove uncorrelatedness in general.
  • Asked: Numerical and general proof.
  • Concept: Decorrelation.
  • Approach: Project.
  • Solution: , . Scores : ; : . ✓ ; ✓. ✓. General: for since eigenvectors of a symmetric matrix with different eigenvalues are orthogonal. ∎
  • Final answer: Variances ; covariance .
  • Key lesson: PCA produces uncorrelated coordinates — this is why it is also called 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 is ; total variance is .
  • PCA is unsupervised.

Connections

C45 (equivalent view), C46 (algorithm), C48 (Fisher comparison).

Mastery checklist

  • Derive via a Lagrange multiplier.
  • Compute PCs of a covariance.
  • Prove uncorrelatedness of scores.

C45. PCA as Minimum Reconstruction Error (Lecture §20.4; Bishop §12.1.2)

Intuition

Instead of “keep the spread”, ask “which -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 and approximate each (centred or not) data point with coefficients depending on but the same for all points. Distortion (by orthonormality). Minimising over the coefficients: So and — lying in the space orthogonal to the principal subspace. Then Minimise subject to : ; , giving . Hence attained by discarding the eigenvectors with the smallest eigenvalues, i.e. keeping the largest. (Covariance matrices are symmetric PSD, so eigenvalues are real and .)

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 say: in the discarded directions, replace the point’s coordinate by the mean’s coordinate.
  • Error curve (Bishop Fig. 12.4b): decreases as grows; .

Worked examples

Example 1 — Very Easy

  • Problem: Eigenvalues . Minimum for .
  • Asked: .
  • Concept: .
  • Approach: Sum the tail.
  • Solution: .
  • Final answer: .
  • Key lesson: Error = discarded eigenvalues.

Example 2 — Easy

  • Problem: Eigenvalues . Smallest retaining of the variance.
  • Asked: .
  • Concept: Cumulative variance.
  • Approach: Cumulative sums (total ).
  • Solution: : ; : ; : ; : ✓.
  • Final answer: (error ).
  • Key lesson: The lecture notes that no principled automatic choice of exists — thresholds like this are a heuristic.

Example 3 — Moderate

  • Problem: Points ; mean . Using the (not necessarily optimal) basis , and , compute if is the discarded axis and if is discarded.
  • Asked: Two distortions.
  • Concept: Formula for .
  • Approach: .
  • Solution: ; ; . Discard : . Discard : . Direct check (discard , replace by the mean ): errors ⇒ ✓.
  • Final answer: vs .
  • Key lesson: Keep the high-variance axis, discard the low-variance one.

Example 4 — Hard

  • Problem: , . Compute if the discarded unit direction is (a) , (b) , (c) .
  • Asked: Three distortions.
  • Concept: .
  • Approach: Evaluate the quadratic form.
  • Solution: (a) . (b) . (c) .
  • Final answer: ; the minimum occurs when discarding the eigenvector of the smaller eigenvalue.
  • Key lesson: for any one-direction discard.

Example 5 — Very Hard

  • Problem: Prove that if is a unit vector then with equality iff is an eigenvector for ; deduce the PCA optimality for and verify with the data of C44 Ex. 3.
  • Asked: Proof and check.
  • Concept: Rayleigh quotient.
  • Approach: Expand in the eigenbasis.
  • Solution: Write with (). , equality iff whenever . For exactly one direction is discarded, so , achieved by the least-variance eigenvector. Check: C44 Ex. 3 data, discarding : errors , mean ✓; discarding instead: .
  • Final answer: ; numeric check vs 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 uses the mean.

Exam traps

  • (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 .
  • Derive .
  • 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)

  1. Subtract each feature’s mean: ; stack as ().
  2. Form the covariance matrix (the lecture uses — same eigenvectors, eigenvalues scaled by ).
  3. Find the largest eigenvalues.
  4. Take the corresponding unit eigenvectors as columns of .
  5. Project: (). Reconstruction: .

Standardising: dividing each centred feature by its standard deviation gives zero mean, unit variance; the covariance matrix then equals the correlation matrix ( perfect positive correlation, uncorrelated). Whitening (sphering): with , define . Then 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 : no good automatic method (variance threshold or elbow of the eigenvalue spectrum).
  • Centring is needed for the covariance to equal .

Worked examples

Example 1 — Very Easy

  • Problem: Centre the data (one feature) and give the covariance.
  • Asked: Centred data and variance.
  • Concept: Step 1–2.
  • Approach: Mean .
  • Solution: ; variance .
  • Final answer: ; .
  • Key lesson: Centring first.

Example 2 — Easy

  • Problem: Two features with data . Centre and compute .
  • Asked: .
  • Concept: Covariance matrix.
  • Approach: Means .
  • Solution: . ; ; .
  • Final answer: .
  • Key lesson: Zero covariance ⇒ PCs are the coordinate axes.

Example 3 — Moderate

  • Problem: Full PCA (to ) of the points : give and the reconstruction of the first point and its error.
  • Asked: , , error.
  • Concept: .
  • Approach: .
  • Solution: (a matrix). Reconstruction of : . Error vector ; . Mean squared error over the four points ✓.
  • Final answer: MSE .
  • Key lesson: Algorithm and theory agree.

Example 4 — Hard

  • Problem: Two features measured in different units: (e.g. grams), (e.g. kilograms). Compare the first PC on raw data and on standardised data.
  • Asked: Two PC1’s.
  • Concept: Scale dependence; correlation matrix.
  • Approach: Raw , then .
  • Solution: Means and . ; ; . Raw: , — essentially feature alone (units dominate). Standardised: , ; ; correlation matrix ⇒ , — both features contribute equally.
  • Final answer: Raw PC1 feature ; standardised PC1 .
  • Key lesson: Standardise when features have different scales.

Example 5 — Very Hard

  • Problem: (so , ). Show that whitening gives identity covariance, and whiten the (centred) point .
  • Asked: Proof and numeric image.
  • Concept: Whitening.
  • Approach: Matrix identity.
  • Solution: ⇒ Cov ✓. Point: ; ⇒ . Check variance along direction after scaling: original variance ⇒ divided by .
  • Final answer: ; Cov.
  • Key lesson: Whitening = rotate to PC axes, then divide each coordinate by .

Common mistakes

  • Using (wrong dimensions) instead of .
  • Forgetting to add the mean back when reconstructing.

Exam traps

  • Divide by or : eigenvectors identical, eigenvalues rescaled.
  • Whitening divides by , not .

Connections

C44–C45, k-means preprocessing (C36), logistic/SVM preprocessing.

Mastery checklist

  • Execute the 5-step algorithm.
  • Explain standardisation vs raw PCA.
  • Derive whitening.

C47. PCA When (High-Dimensional Data; Bishop §12.1.4)

Intuition

If you have 200 images of pixels each, the covariance is — impossible — but the data only span an at-most--dimensional subspace. Solve a small eigenproblem instead and map the eigenvectors back.

Formal derivation

Let be the centred data matrix (rows ). Then and reads . Multiply by and set : an eigenproblem for the matrix with the same non-zero eigenvalues. Conversely, multiply by : , so is an eigenvector of ; normalising (): Rank: centred points span at most dimensions ⇒ at least eigenvalues of are . Cost instead of .

Key insights

  • Never form the matrix when .
  • PCA with is pointless.

Worked examples

Example 1 — Very Easy

  • Problem: points in dimensions. Maximum number of non-zero eigenvalues of ?
  • Asked: Rank bound.
  • Concept: .
  • Approach: Centred points sum to zero.
  • Solution: .
  • Final answer: At most (so eigenvalues equal , ).
  • Key lesson: Centring costs one dimension.

Example 2 — Easy

  • Problem: How many zero eigenvalues does have for , ?
  • Asked: Count.
  • Concept: .
  • Approach: Subtract.
  • Solution: .
  • Final answer: .
  • Key lesson: Almost all directions carry no variance.

Example 3 — Moderate

  • Problem: , centred data with rows . Find the eigenvalues of .
  • Asked: .
  • Concept: Small eigenproblem.
  • Approach: .
  • Solution: . Row sums are ⇒ is a null vector (eigenvalue ). Trace . The other eigenvalues: gives with [check: ✓] and with [check: ✓]. Dividing by : .
  • Final answer: (trace ✓).
  • Key lesson: Solve a problem instead of a one — scaling to huge is the point.

Example 4 — Hard

  • Problem: For Example 3 recover the eigenvectors of the covariance via and verify .
  • Asked: .
  • Concept: Mapping back.
  • Approach: Use the boxed formula.
  • Solution: For (), : ; divide by : , unit length ✓. [: col1·col1; col3·col3; col1·col3] ⇒ ✓. For (), : ; divide by : ✓, ✓.
  • Final answer: PCs are the coordinate axes with variances .
  • Key lesson: The two-step method reproduces the direct answer.

Example 5 — Very Hard

  • Problem: Compare costs for images, pixels, using (a) the eigendecomposition, (b) the route, (c) components by the power method on . Also state how many meaningful components exist.
  • Asked: Operation counts and rank.
  • Concept: Complexity.
  • Approach: , , .
  • Solution: (a) . (b) (plus forming costs and mapping back ). (c) . Meaningful components: at most .
  • Final answer: vs vs ; components.
  • Key lesson: The trick turns an impossible computation into a trivial one.

Common mistakes

  • Forgetting to normalise (it needs the factor).
  • Using the uncentred .

Exam traps

  • Non-zero eigenvalues of and coincide.
  • is not normalised unless scaled.

Connections

C44–C46; singular value decomposition; kernel PCA.

Mastery checklist

  • State the rank bound.
  • Derive .
  • 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 by numbers ; reconstruct (Bishop eq. 12.19–12.20). Smaller ⇒ higher compression, larger error .
  • Visualisation: plot (Bishop’s oil-flow example).
  • Pre-processing: standardisation/whitening (C46).
  • Fisher’s linear discriminant (two classes, within-class scatter ): the direction maximising is .
  • 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 ) — introduced but not developed in the scanned pages.

Worked examples

Example 1 — Very Easy

  • Problem: Images of pixels () are compressed to PCA scores. Compression ratio per image?
  • Asked: Ratio.
  • Concept: Compression.
  • Approach: (ignoring the shared mean and basis).
  • Solution: .
  • Final answer: About fewer numbers per image.
  • Key lesson: The shared basis is amortised over the data set.

Example 2 — Easy

  • Problem: Eigenvalue spectrum . and retained variance for .
  • Asked: , percentage.
  • Concept: .
  • Approach: Total .
  • Solution: ; retained .
  • Final answer: ; .
  • Key lesson: Each extra component adds its eigenvalue to the retained variance.

Example 3 — Moderate

  • Problem: Using the orthonormal basis of C43 (Ex. 3) as “principal axes” for the point with : give the 2-D visualisation coordinates and the reconstruction.
  • Asked: Scores and reconstruction.
  • Concept: Projection for display.
  • Approach: .
  • Solution: Scores . Reconstruction ; error .
  • Final answer: Plot at ; reconstruction error .
  • Key lesson: The picture shows only; is the lost information.

Example 4 — Hard

  • Problem: Two classes in 2-D with means and ; within-class covariance and total covariance dominated by the -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: .
  • Solution: PCA’s first direction is the largest-variance axis, (variance vs along ). Fisher: ; ⇒ . Criterion: ; .
  • Final answer: PCA keeps (class separation ); Fisher keeps (criterion ).
  • Key lesson: PCA is label-blind (Bishop Fig. 12.7).

Example 5 — Very Hard

  • Problem: Combine ideas: a data set has 4 PCs with eigenvalues . (a) How many components are needed for 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 .
  • Solution: (a) Total ; need retained : : (); : (); : . So all components (error only at ; gives ). (b) Whitened covariance ; dropping two components loses of the (now equal) variance — error (in whitened units). (c) After whitening every direction has variance , 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) components; (b) , error (); (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/basis.

Exam traps

  • PCA: unsupervised, uses only ; Fisher: supervised, uses labels.
  • Variance retained .

Connections

C3 (feature extraction), C44–C47, SVM/kNN preprocessing.

Mastery checklist

  • Compute compression ratio, retained variance and error.
  • Contrast PCA with Fisher using the criterion.
  • Explain what whitening does and does not do.