Principal Component
Analysis (PCA)
Discover how PCA transforms high-dimensional data into a compact set of uncorrelated components that capture maximum variance.
What Is PCA?
Principal Component Analysis is a linear dimensionality reduction technique. It finds new orthogonal axes, called principal components, along which the data exhibits the greatest variance.
Think of PCA as rotating the coordinate system so the first axis aligns with the direction of greatest spread, the second axis captures the next greatest spread perpendicular to the first, and so on.
Why Reduce Dimensions?
Visual Intuition
The Covariance Matrix \(\Sigma\)
PCA begins by computing the sample covariance matrix of the centered data. If \(\mathbf{X}\) is an \(n \times p\) matrix whose columns have been mean-centered:
Eigen-decomposition of \(\mathbf{S}\)
Because \(\mathbf{S}\) is symmetric, the Spectral Theorem guarantees it can be decomposed as:
Each eigenvalue \(\lambda_j\) equals the variance of the data along \(\mathbf{v}_j\). The eigenvector with the largest eigenvalue defines PC1.
Computing the Principal Components
PCA vs Factor Analysis
| PCA | Factor Analysis | |
|---|---|---|
| Goal | Maximize variance explained | Identify latent factors |
| Model | No explicit generative model | Assumes \(\mathbf{x} = \boldsymbol{\mu} + \mathbf{L}\mathbf{f} + \boldsymbol{\epsilon}\) |
| Uniqueness | Unique solution (up to sign) | Rotation-dependent |
| Error term | None assumed | Per-variable error \(\boldsymbol{\epsilon}\) |
| Use case | Compression, preprocessing | Theory-driven constructs |
Covariance Matrix vs Correlation Matrix
How to Apply PCA
Worked Example: 2D Data
Suppose we have 5 observations on two variables \(X_1\) and \(X_2\) (already centered):
| Obs. | \(X_1\) | \(X_2\) |
|---|---|---|
| 1 | \(-2\) | \(-1\) |
| 2 | \(-1\) | \(0\) |
| 3 | \(0\) | \(0\) |
| 4 | \(1\) | \(1\) |
| 5 | \(2\) | \(0\) |
Finding the Eigenvalues
Solve \(\det(\mathbf{S} - \lambda\mathbf{I}) = 0\):
Eigenvectors and Projection
For \(\lambda_1 = 2.75\), the eigenvector (normalized) is approximately:
To project observation \(\mathbf{x} = (-2, -1)^\top\) onto PC1:
The score \(z_1 \approx -2.214\) is the coordinate of that observation along the PC1 axis.
The Scree Plot
Proportion of Variance Explained
Two key metrics help you decide how many components to retain:
Common Mistakes
PCA Quick Reference
| Concept | Key Fact |
|---|---|
| Input | Centered (or standardized) data matrix \(\mathbf{X}_{n \times p}\) |
| Decomposition | \(\mathbf{S} = \mathbf{V}\boldsymbol{\Lambda}\mathbf{V}^\top\) |
| PC scores | \(\mathbf{Z} = \mathbf{X}\mathbf{V}_k\) (project onto top \(k\) eigenvectors) |
| Variance of PC\(_j\) | \(\lambda_j\) |
| Total variance | \(\text{tr}(\mathbf{S}) = \sum \lambda_j\) |
| PCs are | Uncorrelated (orthogonal directions) |
| When to standardize | Variables on different scales/units |
Question 1 of 5
What does the first principal component maximize?
Question 2 of 5
If the eigenvalues of a \(4 \times 4\) covariance matrix are \(\lambda_1 = 5,\; \lambda_2 = 3,\; \lambda_3 = 1.5,\; \lambda_4 = 0.5\), what proportion of variance does PC1 explain?
Question 3 of 5
When should you perform PCA on the correlation matrix rather than the covariance matrix?
Question 4 of 5
Which property do the principal components always satisfy?
Question 5 of 5
A dataset has \(p = 10\) variables. After PCA on the correlation matrix, the first 3 eigenvalues are each greater than 1, and the remaining 7 are less than 1. How many components does Kaiser's rule suggest retaining?