The principal components of a data matrix are the eigenvectors of its covariance matrix $S$, ordered by eigenvalue: the $m$th is the unit combination with the largest variance, $v^{\mathsf{T}} S v = \lambda_m$, among those uncorrelated with the earlier ones. The eigenvalues sum to the total variance, the first $M$ components span the $M$-dimensional plane closest to the centered data, and the SVD $\tilde{X} = U D V^{\mathsf{T}}$ gives the same components with $\lambda_m = d_m^2/(n-1)$. On 13 standardized measurements of 178 wines, two components carry 55.4% of the variance and, without using the labels, separate the three cultivars almost completely. Unstandardized, the first component is proline alone (99.8% of the variance): covariance PCA depends on units. The rules for how many components to keep disagree (two to eight), and one data-entry error can claim a component.
The wine data (Aeberhard and Forina, 1992) describe each of 178 wines by 13 chemical measurements. A scatter plot shows two of them at a time, and there are 78 such pairs, none of which shows more than a sliver of the data. Yet the measurements are far from independent. Total phenols and flavanoids have a correlation of 0.865, and flavanoids are correlated above 0.65 with three other measurements. When many measurements move together, a few well-chosen combinations of them can carry most of what they say. Principal component analysis (PCA) finds those combinations: new variables, called principal components, that are uncorrelated with each other and ordered so that the first has the largest possible variance, the second the largest possible variance among variables uncorrelated with the first, and so on. Two of them are enough to draw a map of the wines on which the three grape cultivars separate.
PCA is the most widely used method of dimension reduction, one of the three families of unsupervised learning. It needs no outcome variable: it looks only at how the inputs vary together. This article derives the components, works them by hand for two measurements, shows how to compute them with the singular value decomposition, and covers the practical decisions: how many components to keep, whether to standardize, and how to read the result. Factor Analysis covers a related model that is often confused with PCA.
The idea in two dimensions
Take two of the wine measurements, total phenols and flavanoids, and standardize each one: subtract its mean (2.2951 and 2.0293) and divide by its sample standard deviation (0.6259 and 0.9989). The standardized values have mean 0 and variance 1, and their correlation is $r = 0.8646$. The cloud of 178 points in the left panel of the figure below is a tilted ellipse.
Any direction in the plane can be described by a unit vector $v = (v_1, v_2)$ with $v_1^2 + v_2^2 = 1$. Projecting each wine onto that direction gives one number per wine, $z_i = v_1 x_{i1} + v_2 x_{i2}$, its coordinate along the direction. Some directions spread the wines out more than others. Along the horizontal axis the variance of the projections is 1, the variance of standardized total phenols. Along the diagonal at 45 degrees it is 1.865, and along the other diagonal, at 135 degrees, only 0.135. The right panel traces the variance for every direction. The direction of greatest variance is the first principal component, and the direction perpendicular to it, which here has the least variance, is the second.
Describing each wine by its two coordinates along these new axes, instead of its two original measurements, loses nothing: it is a rotation of the same points. What it gains is concentration. The first coordinate carries $1.865 / 2 = 93.2\%$ of the total variance, and the second only 6.8%. Keeping the first coordinate alone summarizes both measurements by a single number, the position of each wine along the long axis of the ellipse, and loses only the small spread across it. That is dimension reduction.
Pearson (1901) introduced the method from this geometric side, as the problem of finding "lines and planes of closest fit to systems of points in space". Hotelling (1933) developed it from the variance side, in a paper titled "Analysis of a complex of statistical variables into principal components". The geometric view and the variance view used here give the same answer, as shown below. Jolliffe and Cadima (2016, §1) note that the method became computationally feasible on data that were not trivially small only once electronic computers were widely available, decades later.
Deriving the components
Setup
The data form an $n \times p$ matrix $X$, one row per instance and one column per variable. PCA is about variation around the mean, so first center each column by subtracting its mean, and write $\tilde{X}$ for the centered matrix. The sample covariance matrix is
$$S = \frac{1}{n - 1} \tilde{X}^{\mathsf{T}} \tilde{X},$$
a $p \times p$ matrix whose diagonal entry $S_{jj}$ is the variance of variable $j$ and whose entry $S_{jk}$ is the covariance of variables $j$ and $k$. If the columns have also been standardized, $S$ is the correlation matrix $R$.
A linear combination of the variables with coefficient vector $v = (v_1, \dots, v_p)$ gives each instance the value $z_i = \sum_j v_j \tilde{x}_{ij}$, or $z = \tilde{X} v$ for all instances at once. Its mean is zero, because every column of $\tilde{X}$ has mean zero, so its sample variance is
$$\operatorname{var}(z) = \frac{1}{n - 1} z^{\mathsf{T}} z = \frac{1}{n - 1} v^{\mathsf{T}} \tilde{X}^{\mathsf{T}} \tilde{X} v = v^{\mathsf{T}} S v.$$
The first component
The first principal component is the combination with the largest variance. Without a constraint the problem has no answer, because doubling $v$ quadruples the variance, so the coefficients are required to have unit length, $v^{\mathsf{T}} v = 1$ (James, Witten, Hastie and Tibshirani, 2021, §12.2.1). The problem is
$$\text{maximize } v^{\mathsf{T}} S v \quad \text{subject to } v^{\mathsf{T}} v = 1.$$
Introduce a Lagrange multiplier $\lambda$ for the constraint and set the gradient of $v^{\mathsf{T}} S v - \lambda (v^{\mathsf{T}} v - 1)$ with respect to $v$ to zero. Because $S$ is symmetric, the gradient of $v^{\mathsf{T}} S v$ is $2 S v$, and the condition is
$$2 S v - 2 \lambda v = 0, \quad \text{that is,} \quad S v = \lambda v.$$
So $v$ must be an eigenvector of $S$, and $\lambda$ its eigenvalue. Multiplying both sides on the left by $v^{\mathsf{T}}$ and using $v^{\mathsf{T}} v = 1$ gives $v^{\mathsf{T}} S v = \lambda$: the variance of the combination is the eigenvalue. Among all eigenvectors, the largest variance comes from the one with the largest eigenvalue, $\lambda_1$, with eigenvector $v_1$ (Jolliffe and Cadima, 2016, §2a).
A covariance matrix is symmetric, and by the spectral theorem a symmetric $p \times p$ matrix has $p$ real eigenvalues with an orthonormal set of eigenvectors. It is also positive semidefinite, since $v^{\mathsf{T}} S v$ is a variance and cannot be negative, so its eigenvalues are all at least zero. Covariance Matrices and Quadratic Forms states the spectral theorem and proves these consequences for covariance matrices (Theorems 2 and 3). Order them $\lambda_1 \ge \lambda_2 \ge \dots \ge \lambda_p \ge 0$.
Later components
The second component maximizes $v^{\mathsf{T}} S v$ subject to $v^{\mathsf{T}} v = 1$ and to being uncorrelated with the first. The covariance between $\tilde{X} v$ and $\tilde{X} v_1$ is $v^{\mathsf{T}} S v_1 = \lambda_1 v^{\mathsf{T}} v_1$, so when $\lambda_1 > 0$ being uncorrelated is the same as being perpendicular, $v^{\mathsf{T}} v_1 = 0$. With a second multiplier $\mu$ for this constraint, the condition becomes
$$2 S v - 2 \lambda v - \mu v_1 = 0.$$
Multiply on the left by $v_1^{\mathsf{T}}$. The first term gives $2 v_1^{\mathsf{T}} S v = 2 \lambda_1 v_1^{\mathsf{T}} v = 0$, the second gives $0$ because $v_1^{\mathsf{T}} v = 0$, and the third gives $-\mu$, since $v_1^{\mathsf{T}} v_1 = 1$. So $\mu = 0$, and once again $S v = \lambda v$. The second component is therefore an eigenvector perpendicular to $v_1$, and its variance $v^{\mathsf{T}} S v = \lambda$ is largest for the eigenvector with the second-largest eigenvalue.
The $m$th component works the same way, written out. It maximizes $v^{\mathsf{T}} S v$ subject to $v^{\mathsf{T}} v = 1$ and to being uncorrelated with each of the first $m - 1$ components, which, as above, means $v^{\mathsf{T}} v_k = 0$ for $k < m$ when those eigenvalues are positive. With multipliers $\mu_1, \dots, \mu_{m-1}$ the condition is $2 S v - 2 \lambda v - \sum_{k < m} \mu_k v_k = 0$. Multiplying on the left by $v_k^{\mathsf{T}}$ for one $k < m$ gives $2 \lambda_k v_k^{\mathsf{T}} v - 0 - \mu_k = 0$, since the $v_k$ are orthonormal, and $v_k^{\mathsf{T}} v = 0$, so $\mu_k = 0$ for every $k$. Again $S v = \lambda v$ with variance $\lambda$. That the largest variance among such $v$ is $\lambda_m$ follows from the eigenbasis. Extend $v_1, \dots, v_{m-1}$ to an orthonormal basis of eigenvectors $v_1, \dots, v_p$ (Covariance Matrices and Quadratic Forms, Theorem 2). A unit vector perpendicular to $v_1, \dots, v_{m-1}$ is $v = \sum_{k \ge m} c_k v_k$ with $\sum_k c_k^2 = 1$, so $v^{\mathsf{T}} S v = \sum_{k \ge m} c_k^2 \lambda_k \le \lambda_m$, with equality at $v = v_m$. This argument settles the maximum on its own, without relying on the Lagrange condition, and also covers repeated eigenvalues. Covariance Matrices and Quadratic Forms (Theorem 3) proves the same conclusion for the first component without multipliers, from the spectral decomposition. When two eigenvalues are equal, any unit vector in their joint eigenspace is an equally good component, and the components are not unique.
In the terms of James et al. (2021, §12.2.1), the entries of $v_m$ are the loadings of the $m$th component, and the values $z_{im} = \sum_j v_{jm} \tilde{x}_{ij}$, one per instance, are its scores. Stacking the eigenvectors as the columns of a $p \times p$ matrix $V$, all the scores at once are $T = \tilde{X} V$. Their covariance matrix is $V^{\mathsf{T}} S V$, which is diagonal with the eigenvalues on the diagonal: the scores are uncorrelated, and their variances are $\lambda_1, \dots, \lambda_p$.
The two-dimensional example by hand
For two standardized variables with correlation $r$, the covariance matrix is
$$S = \begin{pmatrix} 1 & r \\ r & 1 \end{pmatrix}.$$
Its eigenvalues solve $\det(S - \lambda I) = (1 - \lambda)^2 - r^2 = 0$, so $\lambda = 1 \pm r$. For $\lambda_1 = 1 + r$, the equation $(S - \lambda_1 I) v = 0$ reads $-r v_1 + r v_2 = 0$, so $v_1 = v_2$, and the unit vector is $(1, 1)/\sqrt{2} = (0.7071, 0.7071)$. For $\lambda_2 = 1 - r$ the eigenvector is $(-1, 1)/\sqrt{2}$. With $r = 0.8646$ the eigenvalues are $1.8646$ and $0.1354$, the maximum and minimum of the curve in the figure.
Notice what does not depend on $r$: for any two standardized variables with positive correlation, the first component is their sum and the second their difference, each divided by $\sqrt{2}$. Only the share of variance changes with $r$. Standardizing has given the two variables equal weight by construction.
The first wine in the data has total phenols 2.80 and flavanoids 3.06. Standardized, these are $(2.80 - 2.2951)/0.6259 = 0.8067$ and $(3.06 - 2.0293)/0.9989 = 1.0319$. Its scores are
$$z_1 = \frac{0.8067 + 1.0319}{\sqrt{2}} = 1.3001, \qquad z_2 = \frac{-0.8067 + 1.0319}{\sqrt{2}} = 0.1592.$$
The wine lies 1.30 units along the long axis, on the high-phenol side, and only 0.16 units off it. The scores of all 178 wines have variances 1.8646 and 0.1354, the eigenvalues, and a correlation of zero to the precision of the computation.
Variance explained
The total variance of the data is the sum of the variances of the variables, the trace of $S$. The trace of a symmetric matrix equals the sum of its eigenvalues (Covariance Matrices and Quadratic Forms, Theorem 3, part 2), so
$$\sum_{j=1}^{p} S_{jj} = \sum_{m=1}^{p} \lambda_m.$$
The components redistribute the total variance without changing it. The proportion of variance explained (PVE) by the $m$th component is $\lambda_m / \sum_k \lambda_k$, and the cumulative PVE of the first $M$ components is the sum of the first $M$ of these (James et al., 2021, §12.2.3). For standardized data every variable has variance 1, so the total is $p$ and the PVE is $\lambda_m / p$. That rule, that the eigenvalues add up to the number of variables, holds only for standardized data, the correlation matrix PCA; for a covariance matrix PCA they add up to the total variance in the original units.
PCA on all 13 standardized wine measurements gives these first five components:
| Component | Eigenvalue | PVE | Cumulative PVE |
|---|---|---|---|
| 1 | 4.706 | 0.362 | 0.362 |
| 2 | 2.497 | 0.192 | 0.554 |
| 3 | 1.446 | 0.111 | 0.665 |
| 4 | 0.919 | 0.071 | 0.736 |
| 5 | 0.853 | 0.066 | 0.802 |
The 13 eigenvalues add up to 13. The remaining eight are 0.642, 0.551, 0.348, 0.289, 0.251, 0.226, 0.169 and 0.103, and the last of them carries 0.8% of the variance.
The best low-dimensional approximation
Pearson's view of the method now follows. Keep the first $M$ components and rebuild each instance from its $M$ scores, $\hat{x}_i = \sum_{m=1}^{M} z_{im} v_m$. Because the eigenvectors are orthonormal and the full set rebuilds the data exactly, $\tilde{x}_i = \sum_{m=1}^{p} z_{im} v_m$, the squared length of each centered instance splits into a part along the first $M$ directions and a residual part along the others: $\lVert \tilde{x}_i \rVert^2 = \sum_{m=1}^{p} z_{im}^2$ and $\lVert \tilde{x}_i - \hat{x}_i \rVert^2 = \sum_{m > M} z_{im}^2$, the cross terms vanishing because $v_m^{\mathsf{T}} v_k = 0$ for $m \ne k$. Summed over all instances and divided by $n - 1$, each $\frac{1}{n-1}\sum_i z_{im}^2$ is the variance of the $m$th scores, $\lambda_m$, and this gives
$$\underbrace{\sum_{m=1}^{p} \lambda_m}_{\text{total variance}} = \underbrace{\sum_{m=1}^{M} \lambda_m}_{\text{variance kept}} + \underbrace{\frac{1}{n - 1} \sum_{i=1}^{n} \lVert \tilde{x}_i - \hat{x}_i \rVert^2}_{\text{reconstruction error}},$$
the decomposition given by James et al. (2021, eq. 12.11) with $n$ in place of $n - 1$. The total on the left is fixed, so making the kept variance as large as possible is the same as making the reconstruction error as small as possible. The first $M$ principal components span the $M$-dimensional plane that passes closest to the data in total squared distance (Hastie, Tibshirani and Friedman, 2009, §14.5.1), and the cumulative PVE is the $R^2$ of that approximation. The Singular Value Decomposition in Statistics proves the closest-plane property (Theorem 4). On the wine data, the residual sum of squares of the two-component approximation is 0.4459 of the total sum of squares, exactly $1 - 0.5541$; with five components it is 0.1984.
How many components to keep
There is no single right answer, because the purpose decides it (James et al., 2021, §12.2.4). Several rules are in common use:
- Look for an elbow in a plot of the eigenvalues or the PVE against the component number, a scree plot, and keep the components before the curve flattens. On the wine data the curve falls steeply through the third component and much more slowly after it.
- Keep the components with eigenvalue above 1, a rule often called the Kaiser criterion. For standardized data, an eigenvalue below 1 means the component carries less variance than a single original variable. It keeps three components here.
- Keep enough components to reach a target cumulative PVE. Jolliffe and Cadima (2016, §2a) describe 70% as a common, if subjective, cut-off. Four components reach 70% on the wine data, five reach 80% and eight reach 90%.
- For a plot, keep two, and report how much they show.
- When the components feed a supervised model, choose their number like any other tuning parameter, by Cross-Validation. James et al. (2021, §12.2.4) point out that this setting, unlike the others, has a simple and objective answer.
The rules disagree here, between two and eight components, which is typical of real data. The last components of a dataset are often described as noise, but that is an assumption, not a property of PCA: a component with little variance can still matter, as the separation of two cultivars might, and the next section shows that the amount of variance a direction has depends on the units the variables happen to be measured in.
Standardize first, usually
PCA maximizes variance, and variance depends on units. On the wine data, the variance of proline, measured in milligrams per liter, is 99,166.7; magnesium has a variance of 204.0, and no other measurement has a variance above 11.2. Proline alone holds 99.77% of the total variance of the unstandardized data. PCA on those raw values returns a first component that is proline with a coefficient of 0.9998, explaining 99.8% of the variance, and a second component, magnesium mostly, explaining 0.17%. The analysis has discovered only that proline has the largest numbers. Measuring proline in grams per liter instead would divide its variance by a million and remove it from the first component.
James et al. (2021, §12.2.4) therefore recommend scaling each variable to standard deviation one before PCA when the variables are measured in different units, which is the same as performing PCA on the correlation matrix. When all variables share a unit and their variances are comparable on purpose, such as gene expression levels or the pixel intensities of an image, the covariance matrix may be the better choice, since standardizing would give a near-constant variable the same weight as the most informative one. Jolliffe and Cadima (2016, §2c(i)) stress that the two analyses give different components, not rescaled versions of one another. The same issue arises for every method built on distances, such as k-nearest neighbors and k-means.
Reading the components
Loadings and correlations
Each component is a weighted sum of the standardized measurements, and the weights say what it measures. "Loading" is used in two senses, and the difference matters when comparing software or reading factor analysis output.
In James et al. (2021) and in scikit-learn, the loadings are the entries of the unit eigenvector $v_m$. In the factor analysis tradition, the loadings are the correlations between the variables and the component's scores, and for standardized data these are the eigenvector entries multiplied by $\sqrt{\lambda_m}$. To see why, write $s_m = Z v_m$ for the scores, where $Z$ is the standardized data. The covariance between variable $j$ and the scores is the $j$th entry of $\frac{1}{n-1} Z^{\mathsf{T}} Z v_m = R v_m = \lambda_m v_m$, which is $\lambda_m v_{jm}$. Dividing by the standard deviations, 1 for the variable and $\sqrt{\lambda_m}$ for the scores, gives
$$\operatorname{corr}(z_j, s_m) = \frac{\lambda_m v_{jm}}{\sqrt{\lambda_m}} = v_{jm} \sqrt{\lambda_m}.$$
Squaring and summing over the variables recovers the eigenvalue, $\sum_j v_{jm}^2 \lambda_m = \lambda_m$: an eigenvalue is the sum of the squared correlations of the variables with its component. For the wine data:
| Measurement | $v_1$ | $v_2$ | corr. with PC1 | corr. with PC2 |
|---|---|---|---|---|
| alcohol | 0.144 | 0.484 | 0.313 | 0.764 |
| malic acid | −0.245 | 0.225 | −0.532 | 0.355 |
| ash | −0.002 | 0.316 | −0.004 | 0.499 |
| alcalinity of ash | −0.239 | −0.011 | −0.519 | −0.017 |
| magnesium | 0.142 | 0.300 | 0.308 | 0.473 |
| total phenols | 0.395 | 0.065 | 0.856 | 0.103 |
| flavanoids | 0.423 | −0.003 | 0.917 | −0.005 |
| nonflavanoid phenols | −0.299 | 0.029 | −0.648 | 0.045 |
| proanthocyanins | 0.313 | 0.039 | 0.680 | 0.062 |
| color intensity | −0.089 | 0.530 | −0.192 | 0.837 |
| hue | 0.297 | −0.279 | 0.644 | −0.441 |
| OD280/OD315 | 0.376 | −0.164 | 0.816 | −0.260 |
| proline | 0.287 | 0.365 | 0.622 | 0.577 |
The first component correlates above 0.8 with flavanoids, total phenols and the OD280/OD315 absorbance ratio, all related to the wine's phenolic content, and negatively with nonflavanoid phenols, malic acid and the alkalinity of the ash. It is roughly a phenolic-content axis. The second correlates most with color intensity (0.837) and alcohol (0.764), and negatively with hue. These names are interpretations added afterwards. PCA guarantees only that the components are uncorrelated and ordered by variance, not that each one corresponds to a single meaningful property, and there is no reason the chemistry should divide along exactly these lines.
The signs are arbitrary. If $v$ is an eigenvector, so is $-v$, and flipping a component's sign flips all its scores without changing anything else (James et al., 2021, §12.2.4). Different programs can therefore report opposite signs for the same component. In this article the signs are chosen so that flavanoids load positively on the first component and color intensity on the second, which is also what scikit-learn returns for these data.
Biplots
A biplot (Gabriel, 1971) draws the instances and the variables on the same axes: each instance as a point at its first two scores, and each variable as an arrow, here to its correlations with the two components. Jolliffe and Cadima (2016, §2c(ii)) list the properties that make it readable. Arrows pointing the same way belong to positively correlated variables, arrows at right angles to nearly uncorrelated ones, and an instance far out in the direction of an arrow has a high value of that variable. In two dimensions these readings are approximate, and their accuracy depends on how much variance the two components carry, here 55.4%.
The three cultivars, which played no part in the analysis, occupy three regions of the map. Their mean scores on the first two components are $(2.28, 0.97)$ for cultivar 1, $(-0.04, -1.64)$ for cultivar 2 and $(-2.74, 1.24)$ for cultivar 3. The arrows explain the arrangement: cultivar 1 wines are high in phenolic content, cultivar 3 low, and cultivar 2 wines sit low on the second component, with lighter color and less alcohol. The raw-data analysis in the right panel separates cultivar 1 from the others only to the extent that proline does.
That the cultivars separate is a property of these data, not a promise of PCA. The components are chosen for variance, not for separating groups. A direction that separates two groups perfectly can carry little variance and end up in a late component, and the methods that look for separating directions, such as linear discriminant analysis, are supervised (James et al., 2021, §4.4).
Computing PCA with the SVD
Forming $\tilde{X}^{\mathsf{T}} \tilde{X}$ and finding its eigenvectors works, but PCA is often computed from the singular value decomposition of the centered data matrix instead (Hastie et al., 2009, §14.5.1). Every $n \times p$ matrix can be written
$$\tilde{X} = U D V^{\mathsf{T}},$$
where $U$ is $n \times p$ with orthonormal columns, $D$ is diagonal with the singular values $d_1 \ge d_2 \ge \dots \ge d_p \ge 0$, and $V$ is $p \times p$ and orthogonal (here $n \ge p$; The Singular Value Decomposition in Statistics proves that the decomposition exists, Theorem 1). Then
$$(n - 1) S = \tilde{X}^{\mathsf{T}} \tilde{X} = V D U^{\mathsf{T}} U D V^{\mathsf{T}} = V D^2 V^{\mathsf{T}},$$
which is an eigendecomposition of $(n - 1) S$. So the columns of $V$ are the principal component directions, the eigenvalues are $\lambda_m = d_m^2 / (n - 1)$, and the scores are
$$T = \tilde{X} V = U D V^{\mathsf{T}} V = U D$$
(Jolliffe and Cadima, 2016, §2a). The Academics section's Latent Semantic Indexing derives the SVD itself from the eigendecomposition of $\tilde{X}^{\mathsf{T}}\tilde{X}$ and applies it to a term-document matrix, where the same low-rank approximation is used for retrieval; the difference is that LSI does not center the matrix.
For the standardized wine data the singular values are 28.861, 21.023, 15.999, and so on down to 4.278. Squaring and dividing by $n - 1 = 177$ gives 4.706, 2.497, 1.446, ..., 0.103, the eigenvalues above, and the scores $UD$ agree with $\tilde{X} V$ to within $10^{-13}$ once signs are matched. The SVD route avoids forming $\tilde{X}^{\mathsf{T}}\tilde{X}$, which squares the condition number of the problem and loses accuracy when some components have very small variance, and for a large matrix it can be truncated to compute only the first few components. The eigendecomposition route is cheaper when there are many more instances than variables, since the $p \times p$ matrix is small, and libraries choose between them. scikit-learn's PCA, since version 1.5, uses the eigendecomposition of the covariance matrix by default when there are at least ten times as many rows as columns and at most 1,000 columns (the test in the 1.6.1 source; the documentation says "more than" and "fewer than"), which is the case for the wine data, and an SVD otherwise (full or randomized for dense data) (scikit-learn developers, 2026; checked on version 1.6.1, where the default chooses the covariance route for the $178 \times 13$ wine matrix).
Uses and limits
PCA serves three common purposes (James et al., 2021, §12.2 and §12.2.5):
- Visualization. The first two or three components give the most faithful linear picture of high-dimensional data in two or three dimensions, as the wine map shows.
- Preprocessing. Replacing $p$ correlated inputs by $M$ uncorrelated components can make later methods faster and more stable. Regression on the first few components, principal components regression, avoids the instability that strongly correlated inputs cause in least squares (see Multiple Linear Regression; ridge regression instead keeps every component and shrinks the low-variance ones most), and clustering on a few components can remove noise. Introduction to Unsupervised Learning runs k-means on two wine components and finds nearly the same clusters as on all 13 measurements.
- Compression. Storing $M$ scores per instance and $M$ directions in place of all $p$ values, with the reconstruction error measured by $1 -$ cumulative PVE.
Its limitations follow from its definition:
- It is linear. Components are weighted sums of the inputs, so structure that lies on a curved surface is spread across many components. Nonlinear methods such as kernel PCA and principal curves exist for that case (Hastie et al., 2009, §14.5).
- Variance is not importance. PCA keeps the directions with the most spread, which depend on units and on which variables happen to be included. Five near-duplicate measurements of one property will make that property the first component.
- It is sensitive to outliers. Variances are averages of squares, so a few extreme instances can pull a component toward themselves. Robust versions of PCA address this (Jolliffe and Cadima, 2016, §3c).
- Components need not mean anything. They are uncorrelated summaries, not discovered causes. When the goal is to explain correlations by a small number of underlying traits, factor analysis states that model explicitly, and the comparison there shows how its answers differ.
Worked problems
The three problems extend the article on its own data: the geometric view of Pearson set against regression, the dependence of covariance-matrix PCA on units, and the effect of a single wrong value. The review-pass block of the article's script recomputes every number.
Problem 1 (Pearson's line is not a regression line). For the standardized total phenols ($x$) and flavanoids ($y$), compare the first principal component's line with the least squares lines of $y$ on $x$ and of $x$ on $y$: their slopes, and the mean squared distances they leave, measured perpendicular to the line and vertically.
Approach. A line through the origin at angle $\theta$ has unit direction $(\cos\theta, \sin\theta)$ and unit normal $(-\sin\theta, \cos\theta)$. A point's perpendicular distance to the line is its projection on the normal, so the mean squared perpendicular distance is the variance along the normal, $v^{\mathsf{T}} S v$ with $v$ the normal.
Solution. With $S$ the $2 \times 2$ correlation matrix, the variance along the normal is $$\sin^2\theta + \cos^2\theta - 2 r \sin\theta \cos\theta = 1 - r \sin 2\theta.$$ It is smallest at $\theta = 45°$, slope 1, where it equals $1 - r = 0.1354$, the second eigenvalue: the first component's line is the line of closest fit, as Pearson defined it. The regression of $y$ on $x$ has slope $r = 0.8646$, an angle of 40.85°. Its mean squared perpendicular distance is $1 - r \cdot 2r/(1 + r^2) = (1 - r^2)/(1 + r^2) = 0.1445$, larger, but its mean squared vertical distance is $1 - r^2 = 0.2525$, against $2(1 - r) = 0.2709$ for the component's line. The regression of $x$ on $y$, drawn in the same plane, has slope $1/r = 1.1567$ and the same perpendicular distance, 0.1445, by symmetry. So there are three different lines. Each regression minimizes the errors in one variable, treating the other as known exactly; the component treats the two variables symmetrically and minimizes the distance in both. The component's slope stays at 1 for any positive $r$, while the regression slopes are pulled toward 0 and toward infinity as $r$ falls, which is regression toward the mean. Neither answer is wrong: the regression line is right for predicting flavanoids from phenols, and the component is right for summarizing both by one number.
Problem 2 (covariance PCA changes its answer with the units). Proline is recorded in milligrams per liter. Record it in grams per liter instead and repeat PCA on the covariance matrix and on the correlation matrix.
Solution. Dividing proline by 1,000 divides its variance by $10^6$, from 99,166.7 to 0.099. On the covariance matrix, the first component was proline (weight 0.9998, 99.8% of the variance) and the second magnesium. In grams per liter, magnesium holds 90.7% of the total variance and the first component becomes magnesium (weight 0.9989, PVE 0.909), and the second becomes the alkalinity of the ash (weight 0.9739, PVE 0.051). Proline, now 0.04% of the total variance, has weights of only 0.009 and 0.039 on the first two components, although nothing about the wines changed. The correlation matrix, by contrast, is the same in both units to $10^{-12}$: multiplying a variable by a positive constant multiplies its covariances and its standard deviation by the same constant, so each correlation is unchanged. Correlation-matrix PCA therefore gives identical components and scores in both units. This is the argument for standardizing in one sentence: it makes the answer independent of the units, at the price of deciding that every variable counts equally.
Problem 3 (one wrong value). Suppose the proline of wine 1, 1,065 mg/L, had been entered as 10,650. Follow the error through correlation-matrix PCA.
Solution. The wrong value is 12.22 standard deviations above the mean after standardizing, and it alone supplies 84.3% of the sum of squared standardized proline values, $z^2/(n-1) = 12.22^2/177$. Standardizing divides proline by a standard deviation that the error has inflated, so the 177 correct values are squeezed together and proline's correlations with the other measurements collapse: its largest correlation falls from 0.644 to 0.353. The components follow. The first two eigenvalues fall from 4.706 and 2.497 to 4.502 and 2.304, and the two components together carry 52.4% instead of 55.4%. The plane they span turns by 8.7° (its two principal angles with the old plane are 8.72° and 1.20°). Proline's weight on the first component drops from 0.287 to 0.174, and its largest weight is now 0.652 on the sixth component, on which wine 1 has a score of 7.53 and supplies 44% of the sum of squares: one component has been spent describing one wrong number. The general lesson is the one stated under Uses and limits: a variance is an average of squares, so a single extreme value can claim a component of its own and drain a variable of its real structure. Checking each variable for impossible values before PCA, as in Detecting Outliers, is the first defense, before any robust method; a z-score of 12 is flagged by every rule there.
Open questions
- How many components does parallel analysis keep? Horn (1965) compares each eigenvalue with the eigenvalues of correlation matrices of random data of the same size. Computing the 95th percentile of the $k$th eigenvalue over 1,000 seeded random $178 \times 13$ normal datasets, and counting the wine eigenvalues above it, would add a rule calibrated to the sample size to the four the article compares.
- Which components are stable under resampling? The fourth and fifth eigenvalues, 0.919 and 0.853, are close, and nearly equal eigenvalues make their eigenvectors poorly determined. Bootstrapping the wines (1,000 seeds) and recording the angle between each resampled component and the full-data one, after matching signs, would show which components can be interpreted.
- How much does a robust PCA change the wine components? PCA on a robust covariance estimate, such as the minimum covariance determinant of Detecting Outliers, against classical PCA, with the data-entry error of Problem 3 and without it, would measure what robustness buys and costs on clean data.
- Do sparse components read more clearly? Sparse PCA forces most weights to zero. Fitting it to the standardized wine data for a range of penalties, and recording how much variance is lost as the components become easier to name, would test whether the phenolic and color axes survive simplification.
Where it leads
Principal components are the eigenvectors of the covariance or correlation matrix, ordered by the variance they carry; together they rebuild the data exactly, and the first few span the plane closest to it. What they mean depends on the units, which is why the inputs are usually standardized, and on the variables included. The Statistics collection's The Singular Value Decomposition in Statistics proves the closest-plane property and connects PCA to least squares and ridge regression, and Covariance Matrices and Quadratic Forms proves the spectral facts used here. Factor Analysis fits the latent-variable model that PCA approximates, and Introduction to Unsupervised Learning uses the first two components to draw the wine map and to cluster on. Nonlinear methods of dimension reduction, such as kernel PCA and the embeddings used for visualization, go beyond this article.
In Python
scikit-learn's PCA centers the data but does not scale it, and computes the components by whichever route its svd_solver="auto" policy picks (see the section on the SVD). Standardize first with StandardScaler unless the variables share a unit.
import numpy as np
from sklearn.datasets import load_wine
from sklearn.decomposition import PCA
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
X = load_wine().data
pca = make_pipeline(StandardScaler(), PCA()).fit(X)[-1]
print(pca.explained_variance_ratio_[:3]) # [0.362 0.1921 0.1112]
print(pca.explained_variance_[:3]) # [4.7324 2.5111 1.4542]
v1 = pca.components_[0] # unit eigenvector: loadings in the ISLR sense
corr1 = v1 * np.sqrt(pca.explained_variance_[0] * (len(X) - 1) / len(X)) # correlations with PC1
scores = make_pipeline(StandardScaler(), PCA(n_components=2)).fit_transform(X)
components_ holds one eigenvector per row, and explained_variance_ratio_ the PVE. One detail affects the numbers. StandardScaler divides by the standard deviation computed with $n$ in the denominator, while explained_variance_ uses $n - 1$, so for standardized data the reported eigenvalues are those of the correlation matrix multiplied by $n/(n-1) = 1.00565$ (4.7324 against 4.706), and they add up to 13.073 instead of 13. The proportions are unaffected. The correction in the corr1 line undoes this factor. The code was run with scikit-learn 1.6.1; the 1.9.1 documentation (checked 23 November 2026) describes explained_variance_ with the same $n - 1$ denominator. The numbers in this article are computed by tools/experiments/data-science/principal-component-analysis.py in the site's repository, whose review-pass block checks the worked problems with assertions.
References
- Aeberhard, S., and Forina, M. (1992). Wine [Data set]. UCI Machine Learning Repository. https://doi.org/10.24432/C5PC7J record · 8 pages
- Gabriel, K. R. (1971). The biplot graphic display of matrices with application to principal component analysis. Biometrika, 58(3), 453–467. https://doi.org/10.1093/biomet/58.3.453 record
- Hastie, T., Tibshirani, R., and Friedman, J. (2009). The Elements of Statistical Learning: Data Mining, Inference, and Prediction (2nd ed.). Springer. record · 39 pages
- Horn, J. L. (1965). A rationale and test for the number of factors in factor analysis. Psychometrika, 30(2), 179–185. https://doi.org/10.1007/BF02289447 record
- Hotelling, H. (1933). Analysis of a complex of statistical variables into principal components. Journal of Educational Psychology, 24(6), 417–441, and 24(7), 498–520. https://doi.org/10.1037/h0071325 record
- James, G., Witten, D., Hastie, T., and Tibshirani, R. (2021). An Introduction to Statistical Learning with Applications in R (2nd ed.). Springer. record · 39 pages
- Jolliffe, I. T., and Cadima, J. (2016). Principal component analysis: A review and recent developments. Philosophical Transactions of the Royal Society A, 374(2065), 20150202. https://doi.org/10.1098/rsta.2015.0202 record · 2 pages
- scikit-learn developers (2026). sklearn.decomposition.PCA. scikit-learn 1.9.1 documentation (accessed 23 November 2026). https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html record
- Pearson, K. (1901). On lines and planes of closest fit to systems of points in space. The London, Edinburgh, and Dublin Philosophical Magazine and Journal of Science, 2(11), 559–572. https://doi.org/10.1080/14786440109462720 record · 2 pages
Reviewed: verified, 23 Nov 2026 · citations checked, 23 Nov 2026 · editorial review, 23 Nov 2026 · 10 revisions