Eigenfaces (1991, classic computer vision)
The first PCA-on-images success. Project a face to its top-k PCs, compare projected coordinates. Pre-deep-learning face recognition.
Name things for the reader, not the writer.
Name things for the reader, not the writer.
Principal Component Analysis
Principal Component Analysis (PCA) is the most-used dimensionality reduction technique and a perfect payoff for everything learned in linear algebra. Given data mathbf{x}_1, ldots, mathbf{x}_N in mathbb{R}^D, PCA seeks an orthonormal basis of directions (principal components) such that projecting on
PCA finds orthogonal directions of maximum variance — eigenvectors of the covariance matrix, in decreasing eigenvalue order.
No PCA means no eigenfaces, no LSA topic model, no quick tabular pre-processing, and no intuitive way to decide 'which directions in my data actually matter'.
Principal Component Analysis (PCA) is the most-used dimensionality reduction technique and a perfect payoff for everything learned in linear algebra. Given data , PCA seeks an orthonormal basis of directions (principal components) such that projecting onto the first captures as much variance as possible. The result: a compact, decorrelated representation of high-dimensional data.
Formally, assume the data is centered () and form the covariance matrix . The first principal component is the unit vector maximizing variance of the projection: By the Rayleigh quotient, the maximum is (the largest eigenvalue of ), attained at the corresponding eigenvector. Subsequent components are the remaining eigenvectors in decreasing eigenvalue order, each orthogonal to the previous.
The beauty is that eigenvectors of the covariance matrix are exactly the principal components, and the eigenvalues are exactly the variances captured. Computing PCA reduces to an eigendecomposition of — or equivalently, an SVD of , which is often more numerically stable. The connection: if , then the columns of are principal components and the squared singular values divided by are the variances.
The projected data (where stacks the top eigenvectors) are called scores. Reconstructing gives — another orthogonal projection, this time onto the top- principal subspace. The reconstruction error is minimized; equivalently, PCA is the -rank approximation of with smallest Frobenius norm (Eckart-Young theorem).
PCA has two equivalent derivations — maximum variance (what we just did) and minimum reconstruction error. They are duals: maximizing the variance kept is equivalent to minimizing the variance discarded. In practice, PCA is used for visualization (first 2-3 components), compression (keep 95% of variance), denoising (drop small-eigenvalue components), and as a preprocessing step before clustering or regression. Its limitations — linear, Gaussian, single-scale — motivate kernel PCA, t-SNE, UMAP, and autoencoders.
Worked example — first PC of 4 points: Data has mean . Centered deviations: . The covariance matrix (dividing by ) is approximately — nearly rank-1 with both rows equal to . The top eigenvector is , the diagonal direction, and , — the first PC captures of variance.
Python (in browser)
Expected: Components match up to sign; explained variances match
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
The first PCA-on-images success. Project a face to its top-k PCs, compare projected coordinates. Pre-deep-learning face recognition.
PCA on the term-document matrix yields topics — the precursor to all modern word/document embeddings.
First-line tool to see clustering structure in a thousand-dimensional embedding. Often used as the initialization for t-SNE/UMAP.
from sklearn.decomposition import PCA
proj = PCA(n_components=2).fit_transform(X)
plt.scatter(proj[:,0], proj[:,1])Project onto PCs, divide by singular values — the resulting features have zero mean, unit variance, and zero correlation. Improves convergence for many downstream learners.
Put your understanding to the test. Score + streak + speed all count.
3 quick questions. Get 2 right to mark this lesson complete.