PCA (principal component analysis) is unsupervised dimensionality reduction: it finds the orthogonal directions of maximum variance and projects high-dimensional samples onto the top
k principal components. The first component
v solves the constrained problem
maxvvTΣvs.t.∥v∥=1, where
Σ is the covariance matrix.The Lagrangian
L=vTΣv−λ(vTv−1) differentiated w.r.t.
v gives
Σv=λv — the solution is the top eigenvector of
Σ with variance
=λ (the eigenvalue); the
k-th component is the
k-th largest eigenvector.Hence PCA = SVD of the centered data matrix:
X=UΣVT, the right singular vectors
V are the principal directions, and the projection is
T=XV taking the first
k columns; by the Eckart-Young theorem the top
k components also minimize reconstruction error (max-variance and min-reconstruction are equivalent).Choosing
k: cumulative explained variance ratio
∑i=1dλi∑i=1kλi≥0.95 or the scree-plot elbow; features should be z-scored first.