How this calculation works
Principal component analysis finds orthogonal directions that explain variation in a multivariable data set. This calculator centers observations, optionally standardizes each variable, and returns the complete loading and score matrices. It checks reconstruction of the processed observations, while reporting the sample-covariance eigenvalues and explained-variance fractions.
S=XcᵀXc/(n−1); S V=V diag(lambda); scores=Xc V.A worked example
For observations (2,0),(−2,0),(0,1),(0,−1), both means are zero and the sample covariance is diag(8/3,2/3). The first component explains (8/3)/(10/3)=0.8 of the variation. Keeping both components reconstructs all four processed observations.
Good to know
Complete finite numeric data only, up to six columns. Constant columns cannot be standardized. Repeated eigenvalues make individual loading directions nonunique. PCA is not a significance test, latent-cause proof or supervised predictor.
Reference: NumPy covariance and SVD conventions (opens in a new tab) ↗
Centering defines the variance problem
Each row must describe the same observation across all columns. Centering removes each column mean before the covariance is formed. If rows are accidentally treated as variables, the matrix dimensions and the scientific question change, even though an eigensolver can still return numbers.
Standardization divides by each variable’s sample standard deviation, making the covariance problem a correlation problem. This can substantially change the leading direction when variables have different scales. It is a modeling choice, not a universally superior preprocessing step, so the selector remains visible.
The Principal angles between subspaces calculator covers the nearby task. Subspace angles compare supplied bases; PCA estimates variance directions from observations.
Scores and loadings have different units
A loading column gives a direction in processed variable coordinates, while a score row gives one observation’s coordinates along those directions. Multiplying scores by the transposed loading matrix reconstructs the centered or standardized observations. Adding means and undoing scales is necessary to recover raw measurements.
Eigenvector signs are arbitrary: reversing a loading column and its score column changes no reconstruction. Repeated eigenvalues allow even larger rotations within their common eigenspace. Compare subspaces or reconstructed covariance in those cases rather than treating one package’s sign convention as the correct answer. A zero eigenvalue can be a correct result when observations lie in a lower-dimensional affine subspace. It should not be confused with a failed solve or automatically deleted before the reconstruction check is performed.
A reconstruction check is not a scientific conclusion
Explained variance fractions sum to one across the complete retained basis. A dominant first fraction indicates concentrated sample variation, but does not demonstrate that one physical process caused it. Outliers, measurement scaling and a small sample can each produce an apparently strong principal component.
The default two-variable example is deliberately diagonal, so its covariance eigenvalues and the first fraction can be checked by hand. More general verification compares an independent singular-value decomposition, total covariance trace and the reconstruction residual, giving several checks of the same fitted coordinate system.
Work through a correlated two-variable example
Enter rows 1,1;2,2;3,3 and choose centering. The mean is (2,2), leaving rows (−1,−1),(0,0),(1,1). Dividing the cross-product matrix by n−1 gives covariance [[1,1],[1,1]]. Its eigenvalues are 2 and 0, so a single principal component explains all sample variation. A possible first loading is (1,1)/√2; its scores are −√2,0,√2.
The discarded direction (1,−1)/√2 has zero scores because the observations lie exactly on a line. Reconstructing with the first component therefore loses nothing in this special example. Real data usually have nonzero residual variance. Compare the sum of discarded eigenvalues with the application’s tolerance before deciding that a short representation is adequate.
Connect the eigenvalue calculation to dimensionality reduction
PCA solves a constrained variance maximization: choose a unit vector v to maximize vᵀSv. The maximizing vector is an eigenvector for the largest eigenvalue. Each subsequent vector maximizes the remaining variance while staying orthogonal to the earlier vectors. This explains both why the loading columns are orthogonal and why the eigenvalues can be added to recover total variance.
With only k directions retained, scores times the first k loading columns transposed give the least-squares rank-k approximation to the processed observations. The calculator displays the full basis rather than choosing k for you. Read the cumulative explained fractions, then decide how much approximation is acceptable. A 90% threshold is a user decision, not a statistical law or an automatic guarantee about prediction quality.
Choose between covariance and correlation PCA
Suppose one column measures length in millimetres and another in metres. Center-only PCA preserves their numerical scales, so changing a unit can change the leading component. Standardizing gives each nonconstant column sample variance one, which removes unit magnitudes but also gives a noisy low-variance measurement the same initial weight as a reliable high-variance measurement.
Run both options when scales are debatable and inspect which variables dominate the leading loadings. Record the option with the results. In a predictive workflow, estimate means, standard deviations and loadings on the training observations only; applying PCA to the complete data before a train/test split leaks information. This page analyzes the supplied matrix and does not manage that split or transform new observations automatically.
Recognize unstable directions before interpreting them
When two eigenvalues are close, small changes to observations can rotate their individual loading vectors substantially. A stable two-dimensional subspace can coexist with unstable individual directions. Removing one outlier or adding a few observations is a useful sensitivity check, but it must not become selective deletion merely to obtain a preferred pattern.
Zero reconstruction error with the complete basis is an arithmetic check, not evidence of a good low-dimensional explanation. Likewise, orthogonal scores are uncorrelated in this sample, not necessarily independent random variables. If your question concerns a known outcome, use supervised modeling rather than interpreting the highest-variance direction as the best predictor.
A few questions, answered
Should I standardize the columns?
Use standardization when equal variance weighting is intended; it changes the PCA problem and is not always preferable.
Why do loading signs differ?
An eigenvector and its negative describe the same direction when its scores are reversed too.
How can I reproduce a rank-one result?
Use 1,1;2,2;3,3 with centering. The eigenvalues are 2 and 0 and the explained fractions are 1 and 0; loading signs may reverse.
Does zero covariance between scores mean independence?
No. PCA diagonalizes sample covariance. Independence is a stronger distributional property that does not follow from uncorrelated scores alone.