Find the direction along which your data spreads the most, then describe every point by where it sits along that direction. Rotate the line yourself first, then see what the maths picks.
PCA starts by centring the data on its mean and measuring how the features vary and co-vary. That is the covariance matrix. A large off-diagonal number means the two features rise and fall together, so one direction can describe most of the cloud.
Diagonal entries are the variances of x and y. The off-diagonal entry is their covariance. The trace (sum of the diagonal) is the total variance PCA has to distribute.
Project every point onto your line. The spread of the shadows is the variance on the line; the distances from points to their shadows are the errors. For any line, variance + error equals the total variance, so the line that maximises variance is the same line that minimises error. Click the curve to set the angle.
With more than two features the idea is the same, just with more eigenvectors. Below are 120 samples with six features (A to F). Two hidden factors drive most of them, one feature is mostly noise, and feature F is measured in much larger units. Choose how many components to keep and whether to standardise first.
Loadings are the eigenvector entries: how much each original feature contributes to a component. The sign of a whole component is arbitrary, so compare sizes, not signs. Common ways to choose k, such as reaching a target share like 90% or stopping at the elbow of the scree plot, are heuristics, not rules: the right k depends on what you will do with the result.
Numbers in A to E come from the 2D points in the playground and update live.
Eigenvectors are the principal directions (orthogonal unit vectors). Eigenvalues are the variance along them. The total variance is the trace of C, which equals the sum of the eigenvalues.
Keeping only the top k components and rebuilding the points leaves an error equal to the variance you dropped (with the n−1 versus n convention shown). Here k = 1.
Add a point far from the cloud and watch PC1 swing towards it. PCA is based on squared distances, so extreme points pull hard.
When the spread is equal in every direction, the two eigenvalues are close and PC1 has no clear direction. Drag points and watch it jump.
With standardising off, the feature with the biggest units dominates PC1. Switch it on and compare the loadings.