Algorithm

Center data. Compute covariance matrix. Eigendecompose. Top-k eigenvectors = principal components. Project.

Advertisement

SVD version

X = UΣV^T. Principal components = right singular vectors V. Avoids explicit covariance computation.

Advertisement

Variance explained

Fraction of variance retained = sum of top-k eigenvalues / sum of all. Choose k for 95% typically.