The Shadow on the Wall
When you cast a shadow of your 3D hand onto a flat 2D wall, you lose one dimension of information. How can you orient your hand so that the shadow retains the maximum amount of detail and recognizable structure?
Centering & Variance Maximization
PCA begins by shifting the data so its mean is at the origin . It then rotates the coordinate axes to align with the directions of maximum spread (variance), discarding axes with minimal information.
Interactive Covariance & Eigenvector Lab
Inspect the blue principal component vector . Red dotted lines show the orthogonal projection error discarded when compressing 2D points onto the line.
Predicting Reconstruction Error
If all data points lie on a perfectly straight diagonal line (), what percentage of variance is captured by the first principal component PC1?
What is the explained variance ratio of PC1 when data is perfectly collinear?
The Covariance Matrix & Spectral Theorem
The sample covariance matrix is symmetric and positive semi-definite. By the Spectral Theorem, it has real eigenvalues and orthogonal eigenvectors that form a new coordinate basis.
Mathematical Formulation
Eigenvector defines the direction of the first principal axis. The corresponding eigenvalue equals the exact variance of the projected data points along that axis.
Break The Algorithm: The Swiss Roll & Label Blindness
Because PCA is strictly linear and unsupervised, it fails on non-linear manifolds (like a spiral Swiss Roll) and can accidentally discard low-variance dimensions that contain crucial classification boundaries.
Scikit-Learn Implementation
Compute PCA projection and variance ratios in Python.
import numpy as np
# 1. Center data
X_c = X - np.mean(X, axis=0)
# 2. Covariance matrix
C = np.cov(X_c, rowvar=False)
# 3. Eigen decomposition
eigenvalues, eigenvectors = np.linalg.eigh(C)Scikit-Learn uses SVD (Singular Value Decomposition) directly on X_c rather than computing X_c^T X_c to maintain numerical precision and avoid squaring condition numbers.
Diagnostic Understanding Check
Test your understanding of spectral dimensionality reduction.
Mastery & Synthesis
You have mastered data centering, covariance matrices, and spectral projections. You have completed the 10 Essential Core Algorithm Stages in ML in Motion! Next, advance into Stage 11: Model Evaluation & Generalization to validate your models rigorously.