Principal Component Analysis (2-D → 1-D)
Interactive lab
Try it: Principal Component Analysis (2-D → 1-D)
How PCA compresses 2-D points to a 1-D code y = Wx with W = u^T, where u is the top eigenvector of A = X^T X, recovers them as x~ = Uy, and why no other direction has a smaller total squared reconstruction error.
How it works
- Optionally centre the data by subtracting the mean.
- Form A = X^T X, the sum of x_i x_i^T (A / m is the covariance matrix).
- Find A's eigenvalues and the unit eigenvector u of the largest one (closed form for a symmetric 2×2 matrix).
- Compress each point to y_i = u · x_i and recover x~_i = u y_i on the principal line.
- The total squared reconstruction error equals the smaller eigenvalue; compare it with any other direction.
Default run (7 steps): 9 points in 2-D. Goal: a 1-D representation y = W x (W is 1x2) and a recovery x~ = U y that keep the total squared reconstruction error small. … Your direction at 90° (0, 1) would give error 34.8889 — 31.6146 more than PCA's 3.2743. No unit direction beats u.
Simplified: Only 2-D data reduced to one dimension (2–12 points), so the eigenproblem has a closed form; real PCA works with many dimensions and numerical eigen-solvers.
Educational simulation
Loading the simulation…