On this page
Say you measured two things about five students, or five stars, or five samples in a lab. Plot them and the points lean along a diagonal. Principal component analysis (PCA) asks one question: which direction through this cloud carries the most spread, and which carries the least? Answer it and you can describe the data with fewer numbers while losing as little as possible.
What is principal component analysis?
PCA is a technique for reducing the dimensionality of a dataset while minimising information loss, by creating new uncorrelated variables that successively maximise variance (Jolliffe and Cadima, Philosophical Transactions of the Royal Society A, 2016). The same review notes that finding these new variables, the principal components, reduces to solving an eigenvalue and eigenvector problem.
The idea is old. Karl Pearson described fitting lines and planes of closest fit to systems of points in space in 1901, and Harold Hotelling's 1933 paper put the name in its title: Analysis of a complex of statistical variables into principal components.
In one sentence: the principal components are the eigenvectors of the data's covariance matrix, ordered by their eigenvalues, and each eigenvalue is the variance of the data along that eigenvector.
How do you calculate PCA by hand?
Take five points: (1, 2), (2, 1), (3, 3), (4, 5) and (5, 4). Every step below is arithmetic you can check with a pencil.
Centre. Both means are 3, so subtract 3 from every coordinate. The centred points are (−2, −1), (−1, −2), (0, 0), (1, 2) and (2, 1).
Covariance. Divide sums of products by n − 1 = 4. Sum of x² is 10, sum of y² is 10, sum of xy is 2 + 2 + 0 + 2 + 2 = 8. So var(x) = var(y) = 2.5 and cov(x, y) = 2. The covariance matrix is C = [[2.5, 2], [2, 2.5]].
Eigenvalues. Solve det(C − λI) = 0, that is (2.5 − λ)² − 4 = 0. So 2.5 − λ = ±2, giving λ₁ = 4.5 and λ₂ = 0.5.
Eigenvectors. For λ₁ = 4.5, (C − 4.5I)v = 0 gives −2a + 2b = 0, so v₁ = (1, 1)/√2. For λ₂ = 0.5 you get v₂ = (1, −1)/√2. They are perpendicular, as eigenvectors of a symmetric matrix must be.
Scores. Project each centred point onto v₁: (x + y)/√2 gives −3/√2, −3/√2, 0, 3/√2, 3/√2. The sum of squares is 18, and 18/4 = 4.5, exactly λ₁. That is the check that you have it right.
What does the explained variance ratio tell you?
The explained variance ratio of a component is its eigenvalue divided by the sum of all eigenvalues; scikit-learn reports it as the percentage of variance explained by each of the selected components. In our example PC1 explains 4.5/5 = 90% and PC2 explains 0.5/5 = 10%.
So one number per point, the PC1 score, keeps 90% of the spread in these five points. Dropping PC2 loses the small wobble across the diagonal and keeps the trend along it. With real data, people keep enough components to reach a level of explained variance they are happy with, and look at what each kept direction means.
Why do you centre the data before PCA?
The covariance matrix measures spread about the mean, so the formula assumes centred data. The scikit-learn PCA documentation says the input data is centred, but not scaled, for each feature before the SVD is applied (scikit-learn PCA). Skip centring and the first direction tends to point from the origin towards the mean of the cloud, which tells you where the data sits, not how it varies.
Scaling is a separate choice. If one variable is in centimetres and another in kilograms, the one with bigger numbers dominates. Standardise each variable first and you are doing PCA on the correlation matrix instead of the covariance matrix.
How is PCA related to the SVD?
Write the centred data as a 5 × 2 matrix X and take its singular value decomposition, X = USVᵀ. Then XᵀX = VS²Vᵀ, so the columns of V are the eigenvectors of the covariance matrix, and each eigenvalue is s²/(n − 1). In our example the singular values are √18 and √2, and 18/4 = 4.5 and 2/4 = 0.5, the same eigenvalues as before. Working on X directly means you never have to form XᵀX: scikit-learn's PCA describes itself as linear dimensionality reduction using the singular value decomposition of the data, though it also offers a solver that builds the covariance matrix.
If eigenvalues, determinants or variance still feel shaky, the Fermi Concept Library gives each concept in mathematics its own lesson, and the Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning rather than printing an answer.



