For AI agents: use /llms.txt for the Nakafa content index.
Let contain observations of features. begins by subtracting each feature mean:
The sample covariance matrix is
It is symmetric positive semidefinite. It may be singular when features are linearly dependent or when .
Centering is mandatory. Standardizing each feature to unit variance is a separate modeling choice that is often appropriate when features use incomparable units. It changes the question from directions of largest absolute variance to directions of largest standardized variance.
By the spectral theorem,
The first principal direction solves
Each later direction maximizes the same variance subject to being orthogonal to all earlier directions. The transformed coordinates, or scores, are
The sample covariance of the scores is diagonal:
The principal components are therefore uncorrelated. They are not generally independent. Independence follows in special models, including a jointly Gaussian distribution.
The proportion of total sample variance explained by component is
Keeping the first eigenvectors in gives the scores and reconstruction
Among all rank- linear reconstructions, this choice minimizes squared reconstruction error. With the sample-covariance convention above,
can also be computed through the following thin singular value decomposition:
The right singular vectors give the principal directions, while the eigenvalues satisfy:
Using avoids forming , which would square the condition number. also works well when is rectangular or rank deficient.
The covariance ellipse is rotated by the following angle:
The variances along the two principal axes are and . The rotation and covariance matrices are:
The principal directions are the columns of :
The variance ratio explained by the first component is calculated from the two eigenvalues:
The result is the fraction of the total variance explained by the first component.
| Check | Reason |
|---|---|
| Center with training-set means only | prevents data leakage and preserves the learned coordinate system |
| Review feature units and scaling | high numerical variance can otherwise dominate for the wrong reason |
| Choose from validation needs | explained variance does not measure predictive relevance |
| Remember eigenvector signs are arbitrary | and define the same component |
| Inspect nonlinear structure and outliers | is a linear, variance-based summary and can be sensitive to both |
identifies directions with large variance. Variance alone does not establish a cause. One principal component may combine many original features. A direction with low variance may still carry a signal needed by a later prediction or classification task.
Published: . Updated: .