Principal Component Analysis
Principal Component Analysis — Project data onto the directions of greatest variance.
PCA finds the directions in which your data varies most and projects onto them, compressing many correlated features into a few meaningful axes while keeping as much information as possible.
- Data
- Axis under test
- First PC (and best-fit plane)
- Residual thrown away
PCA controls
The idea in plain words
PCA finds the directions along which your data varies the most and projects onto them. Rotate the projection axis by hand and the “variance captured” meter peaks exactly at the first principal component — you discover PCA instead of being told it.
It’s a linear method, though. Hand it a curved manifold like a swiss roll and it can only flatten by projection — it can’t unroll the sheet. That limitation is what motivates t-SNE and UMAP.
Now, the math
The principal components are the eigenvectors of the covariance matrix:
- the k-th principal component (a direction).
- its eigenvalue — the variance captured along that direction.
- the data covariance matrix.
▸ Show the derivation
The direction of maximum variance is the top eigenvector of the covariance matrix; the explained variance ratio is its eigenvalue over the total. Projecting onto the first few components keeps the most information for the fewest dimensions — but only along straight axes, so curved structure is lost.
Trace it by hand
Four 2-D points: (0,0), (2,1), (1,2), (3,3). We build the covariance matrix, extract its eigenvectors with the repo's Jacobi eigensolver, and read off the explained variance (eigenvector entries rounded to 3 decimal places).
Step 1 — center the data at its mean
PCA measures spread around the mean, so everything below uses deviations from (1.5, 1.5).
Step 2 — the covariance matrix
The large positive off-diagonal says the two features move together — the cloud is stretched along the diagonal.
Step 3 — its eigenvalues and eigenvectors
0.707 is 1 over root 2 — the first principal component points exactly along the 45 degree diagonal, matching the covariance's hint.
Step 4 — explained variance ratio
Projecting onto v1 alone keeps 90 percent of the variance while halving the dimensions.
What just happened: The covariance matrix's eigenvector (0.707, 0.707) is the diagonal direction the four points visibly stretch along, and its eigenvalue says that one axis holds 90 percent of the variance — compression with a known, computed cost.
Now Break It
Try this: Dropping to too few components loses the structure — reconstruction becomes a blur.
Control: Components-to-keep slider (set to 1)
What happens: Too much compression! Keeping only one component throws away the structure — reconstruction fails.
Where principal component analysis is used
Principal Component Analysis finds the directions along which data varies most and projects onto them, making it a staple for compression, visualization, and noise reduction. Analysts use it to squeeze dozens of correlated features into a handful of components before feeding them to a model, which speeds training and reduces overfitting. It underlies eigenfaces in face recognition, helps genomics researchers visualize population structure from thousands of genetic markers, and denoises signals by discarding low-variance components that often carry mostly noise. Because the components are ordered by how much variance they explain, PCA also gives a clear way to decide how many dimensions to keep, and projecting onto the first two or three components produces a quick, interpretable map of an otherwise unwieldy high-dimensional dataset.
The biggest misconception is that PCA finds the features most useful for prediction; it actually finds directions of maximum variance, which are not always the directions that matter for a label, so a low-variance component can still be the discriminative one. PCA is also strictly linear: it captures linear correlations and cannot unfold curved manifolds, where kernel PCA or methods like UMAP do better. Two practical pitfalls matter. First, PCA is sensitive to feature scaling, so features with large units dominate unless you standardize first. Second, the components are linear combinations of all original features, which makes them powerful but hard to interpret, and reifying a component as a single real-world concept is usually a mistake.
Frequently asked questions
What exactly is a principal component?
How many components should I keep?
Do I need to standardize my data before PCA?
Is PCA a feature selection method?
Why does PCA fail on nonlinear data?
Written & reviewed by the ML Visualization team · Last updated .