Mathematics and Statistics for AI Beginner 15 minutes

Eigenvalues and Singular Value Decomposition

The directions a transformation does not rotate, and how SVD leads to dimensionality reduction and principal component analysis.

Your progress in the track0%

Eigenvectors

$$A v = \lambda v$$

The transformation \(A\) leaves the direction \(v\) as it is and stretches it by the factor \(\lambda\). For a symmetric matrix (such as a covariance matrix), the eigenvalues are real and the eigenvectors are orthogonal.

Singular value decomposition

$$X = U \Sigma V^\top$$

  • \(U\) and \(V\) are orthogonal matrices.
  • \(\Sigma\) is diagonal, and its elements are the singular values in descending order.
  • Keeping the largest \(k\) values gives the best rank-\(k\) approximation of the matrix (the Eckart–Young theorem).

From SVD to PCA

  1. Centre the data by subtracting the mean of each feature (from the training data).
  2. Compute the SVD of the centred matrix; the columns of \(V\) are the principal components.
  3. The proportion of variance explained by each component is proportional to the square of its singular value.
from sklearn.decomposition import PCA
from sklearn.datasets import load_digits
X, _ = load_digits(return_X_y=True)          # 64 features
pca = PCA(n_components=0.95).fit(X)          # keep 95% of the variance
print(pca.n_components_, pca.explained_variance_ratio_[:3])

When is PCA not enough?

  • Non-linear structure in the data (Kernel PCA, UMAP or autoencoders are used instead).
  • When the goal is separating classes, since the largest variance does not necessarily carry the most important information for classification.

To avoid leakage, PCA is fitted on the training data only inside a Pipeline, then applied to the test data.

Lesson terms

Eigenvector
A non-zero vector v satisfying Av = λv, meaning the transformation does not change its direction.
Singular value decomposition
Decomposing any matrix into the product of two orthogonal matrices and a diagonal matrix of non-negative singular values.
Principal component analysis
A dimensionality reduction method that projects the data onto the orthogonal directions of greatest variance.

Abstract

An eigenvector of a square matrix is a direction that does not change when the transformation is applied, except for stretching by the eigenvalue. Singular value decomposition (SVD) writes any matrix in the form U Σ Vᵀ, and the largest singular values capture most of the structure. Principal component analysis (PCA) projects centred data onto the directions of greatest variance, which are the eigenvectors of the covariance matrix.

Review questions

  1. What does a negative eigenvalue mean?

    That the transformation reverses the direction of the eigenvector in addition to stretching or shrinking it.

  2. Why do we centre the data before PCA?

    Because PCA looks for directions of variance around the mean; without centring, the first component may capture the position of the mean instead of the variance.

Sources and references

  1. Deisenroth, Faisal & Ong — Mathematics for Machine Learning (Ch. 4 & 10)
  2. scikit-learn — PCA
  3. Gilbert Strang — MIT 18.06 Linear Algebra

Complete the lesson