PCA Calculator
Principal component analysis on your own data: the covariance or correlation matrix, its eigenvalues and loadings, the share of variance each component explains, and the data in the new coordinates, with a cloud you can flatten onto PC1.
Data
One sample per row and one feature per column, 2 to 6 features. Type, paste from a spreadsheet or CSV, or start from an example.
Principal components
Updates as you type.
8 samples and 2 features.
PCA of the covariance matrix. A feature measured in bigger numbers carries more weight.
Covariance matrix
Variance by component
Keeping 1 of 2 components keeps 98.7% of the variance.
Loadings
Each row is one component's direction as a unit vector: how much of each feature it's made of. A sign is arbitrary; flipping a whole row gives the same direction.
Data in the new coordinates
Each sample's position along the kept components: its centered row dotted with each loading.
Values marked ≈ are rounded. Shares, loadings, and coordinates are always rounded.
What PCA does
Principal component analysis finds new axes for your data. The first, PC1, points the way the samples spread out the most. The second is the direction of most remaining spread at a right angle to the first, and so on. Each component's variance is how much the data spread along it, and the components together hold exactly the variance the original features had.
Often the first two or three components hold almost all of it. Keeping only those turns many features into a few, with little lost. That's dimensionality reduction: for plotting high-dimensional data, cutting noise, or feeding a smaller input to another model.
Where the components come from
The directions are the eigenvectors of the covariance matrix, which the Covariance Matrix Calculator builds:
where is the data with each column's mean subtracted. Because is symmetric, its eigenvectors are at right angles to each other and its eigenvalues are never negative. The variance along a unit direction is , and the largest that can be is the top eigenvalue, reached at its eigenvector. The Eigenvalue and Eigenvector Calculator shows the same decomposition for any matrix.
Libraries such as scikit-learn get the same directions from the SVD of instead: the right singular vectors are the eigenvectors of , and . The SVD Calculator computes that factorization.
Reading the result
- Share of variance (scikit-learn's
explained_variance_ratio_) is each eigenvalue divided by their sum. The running total says how much a few components keep. - Loadings are the eigenvectors: PC1 = height weight reads as "overall size". A component's sign is arbitrary, so a whole row of loadings can flip without changing anything.
- The data in the new coordinates are the projections , where holds the first loadings as columns. Their variances are exactly the eigenvalues, and they're uncorrelated with each other.
- The scree chart shows the shares falling off. A common rule is to keep components up to where the running total reaches 90% or so, or up to the "elbow" where the bars flatten out.
Center only, or standardize?
PCA of the covariance matrix weighs a feature by its variance, which depends on its units. Measure area in square meters next to the number of rooms and area takes nearly all of PC1, because its numbers are bigger, not because it matters more. The "Different units" example shows this.
Standardizing divides each feature by its standard deviation first, so every feature has variance 1 and PCA works on the correlation matrix. Use it when the features are in different units. Leave it off when they share units and their spread is meaningful, like pixel brightness or scores on the same scale.
Exact and rounded values
With the data only centered, the covariance matrix has exact fractions, and when its eigenvalues can be written exactly (whole numbers, fractions, or square roots for two features) this calculator shows them that way in fractions view. Standardizing divides by square roots, so those results are rounded. Loadings, shares, and coordinates are always rounded, since unit vectors almost always involve square roots.
Related calculators
The linear algebra underneath, and more of the machine learning section.
Covariance Matrix Calculator
Paste up to 100 samples of 6 features and get the means, centered data, exact covariance matrix, and correlation matrix, with a draggable scatter and covariance ellipse.
Eigenvalue and Eigenvector Calculator
Find eigenvalues and eigenvectors with exact fractions, square roots, and complex values, plus each multiplicity. Spin a vector until the matrix only stretches it.
SVD Calculator
Find the singular value decomposition UΣVᵀ of any matrix up to 6×6, with rank and condition number. Watch a circle turn, stretch into an ellipse, and turn again.
Linear Regression Calculator
Fit a linear model to up to 6 features with an intercept. Exact coefficients from the normal equations, predictions, residuals, MSE, R², and optional ridge regularization.