Chapter 1: The Geometry of Data Compression — Centering, Projections, and Orthogonal Shadows

Principal Component Analysis (PCA) begins with a concrete engineering question: how do you compress a high-dimensional cloud of observations onto a lower-dimensional subspace while losing as little geometric structure as possible? Before a single matrix determinant or eigenvalue ever enters the picture, PCA is fundamentally a shadow-casting problem in Euclidean space.

When we approach PCA from the top down, we start with raw data points, shift their center of gravity to the origin, project every point perpendicularly onto a candidate axis u\mathbf{u}, and measure the distortion caused by flattening the cloud. Understanding these three geometric operations—centering, orthogonal projection, and perpendicular residuals—unlocks the entire logic of dimensionality reduction.

In this Article

1. The Top-Down Problem: Compressing 2D Data onto a 1D Line

Suppose you record two correlated measurements—say height xi1x_{i1} and arm span xi2x_{i2}—for nn individuals. Each person is represented as a column vector xi=[xi1xi2]\mathbf{x}_i = \begin{bmatrix} x_{i1} \\ x_{i2} \end{bmatrix} in R2\mathbb{R}^2. Because height and arm span grow together, the scatter plot forms a tilted elliptical cloud rather than a uniform square.

If storage or downstream modeling requires compressing those two numbers per person into a single summary score zi∈Rz_i \in \mathbb{R}, we must choose a straight line passing through the center of the cloud and replace each 2D point xi\mathbf{x}_i with its closest point x^i\hat{\mathbf{x}}_i on that line.

      x2 (Arm Span, Centered)
       ^
       |                * x_i (True 2D Data Point)
       |               / \
       |              /   \  e_i (Perpendicular Error)
       |             /     v
       |      *     /      (o) x_hat_i = (x_i . u) u  [Shadow on Line]
       |           /      /
-------+----------0------+-----------------> x1 (Height, Centered)
       |         /      /
       |   (o)  /      /   <-- Candidate Line spanned by unit vector u
       |    ^  /
       |     \/
       |     *

2. Step 1: Mean-Centering Shifts the Origin to the Cloud Centroid

A linear subspace (a line or plane in linear algebra) must pass through the coordinate origin 0\mathbf{0}. If our raw data cloud is centered around μ=[170172]\boldsymbol{\mu} = \begin{bmatrix} 170 \\ 172 \end{bmatrix} centimeters, any line forced through [00]\begin{bmatrix} 0 \\ 0 \end{bmatrix} would primarily point from the origin toward the average human size rather than capturing person-to-person variation.

To isolate internal variation, we compute the sample mean vector μ=1n∑i=1nxiraw\boldsymbol{\mu} = \frac{1}{n}\sum_{i=1}^n \mathbf{x}_i^{\text{raw}} and subtract it from every observation:

xi=xiraw−μ,so that1n∑i=1nxi=0\mathbf{x}_i = \mathbf{x}_i^{\text{raw}} - \boldsymbol{\mu}, \quad \text{so that} \quad \frac{1}{n}\sum_{i=1}^n \mathbf{x}_i = \mathbf{0}

This translation preserves every pairwise distance and angle between observations while placing the centroid of the cloud directly at 0\mathbf{0}.

3. Step 2: Casting Perpendicular Shadows with Unit Vectors

Once the cloud is centered at 0\mathbf{0}, any candidate line through the origin is defined by a unit direction vector u∈Rd\mathbf{u} \in \mathbb{R}^d satisfying ∥u∥=uTu=1\|\mathbf{u}\| = \sqrt{\mathbf{u}^T \mathbf{u}} = 1. Restricting u\mathbf{u} to unit length ensures that u\mathbf{u} acts purely as a directional compass without stretching or shrinking our measurement scale.

Core Projection Formulas: For any centered observation xi\mathbf{x}_i and unit vector u\mathbf{u} (with uTu=1\mathbf{u}^T\mathbf{u} = 1):

  • Scalar Score (1D Coordinate along the line): zi=xi⋅u=uTxiz_i = \mathbf{x}_i \cdot \mathbf{u} = \mathbf{u}^T \mathbf{x}_i
  • Reconstructed Point (2D/3D Shadow on the line): x^i=ziu=(uTxi)u=(uuT)xi\hat{\mathbf{x}}_i = z_i \mathbf{u} = (\mathbf{u}^T \mathbf{x}_i)\mathbf{u} = (\mathbf{u}\mathbf{u}^T)\mathbf{x}_i

4. Step 3: Orthogonal Reconstruction Error vs. Regression Residuals

When we approximate xi\mathbf{x}_i by its shadow x^i\hat{\mathbf{x}}_i, the residual vector is ri=xi−x^i\mathbf{r}_i = \mathbf{x}_i - \hat{\mathbf{x}}_i, and its Euclidean length is the orthogonal reconstruction error ei=∥xi−(xi⋅u)u∥e_i = \|\mathbf{x}_i - (\mathbf{x}_i \cdot \mathbf{u})\mathbf{u}\|.

PropertyOrdinary Least Squares (OLS Regression)Principal Component Analysis (PCA)
Variable RolesAsymmetric: x1x_1 is noise-free predictor, x2x_2 is responseSymmetric: all features x1,x2,…,xdx_1, x_2, \dots, x_d treated equally
Error DirectionVertical distance parallel to the x2x_2 axisPerpendicular (orthogonal) distance to the line u\mathbf{u}
Rotation InvarianceNot rotation-invariant; swapping axes changes the lineFully rotation-invariant; geometry depends only on point cloud

5. Complete Worked Numerical Example

Consider a raw 2D dataset of n=2n = 2 points: x1raw=[54]\mathbf{x}_1^{\text{raw}} = \begin{bmatrix} 5 \\ 4 \end{bmatrix} and x2raw=[12]\mathbf{x}_2^{\text{raw}} = \begin{bmatrix} 1 \\ 2 \end{bmatrix}.

  1. Center the data: The mean vector is μ=12[5+14+2]=[33]\boldsymbol{\mu} = \frac{1}{2}\begin{bmatrix} 5+1 \\ 4+2 \end{bmatrix} = \begin{bmatrix} 3 \\ 3 \end{bmatrix}. Subtracting μ\boldsymbol{\mu} gives x1=[21]\mathbf{x}_1 = \begin{bmatrix} 2 \\ 1 \end{bmatrix} and x2=[−2−1]\mathbf{x}_2 = \begin{bmatrix} -2 \\ -1 \end{bmatrix}.
  2. Project onto a candidate axis: Let us test the horizontal unit axis u=[10]\mathbf{u} = \begin{bmatrix} 1 \\ 0 \end{bmatrix}. The 1D score for x1\mathbf{x}_1 is z1=[21][10]=2z_1 = \begin{bmatrix} 2 & 1 \end{bmatrix}\begin{bmatrix} 1 \\ 0 \end{bmatrix} = 2.
  3. Reconstruct and measure error: The shadow on the horizontal axis is x^1=2[10]=[20]\hat{\mathbf{x}}_1 = 2\begin{bmatrix} 1 \\ 0 \end{bmatrix} = \begin{bmatrix} 2 \\ 0 \end{bmatrix}. The residual vector is x1−x^1=[01]\mathbf{x}_1 - \hat{\mathbf{x}}_1 = \begin{bmatrix} 0 \\ 1 \end{bmatrix}, giving squared error e12=02+12=1e_1^2 = 0^2 + 1^2 = 1.
  4. Compare with the optimal axis: If instead we choose u∗=[2/51/5]\mathbf{u}^* = \begin{bmatrix} 2/\sqrt{5} \\ 1/\sqrt{5} \end{bmatrix}, then z1=4+15=5z_1 = \frac{4+1}{\sqrt{5}} = \sqrt{5}, the reconstructed point is x^1=5[2/51/5]=[21]\hat{\mathbf{x}}_1 = \sqrt{5}\begin{bmatrix} 2/\sqrt{5} \\ 1/\sqrt{5} \end{bmatrix} = \begin{bmatrix} 2 \\ 1 \end{bmatrix}, and the reconstruction error drops to e12=0e_1^2 = 0!

6. Spatial Analogy and Where It Breaks Down

Think of the 2D data cloud as a constellation of glowing fireflies frozen in a dark room, and the unit vector u\mathbf{u} as a straight metal rod passing through the center of the swarm. Projecting each point onto u\mathbf{u} is like connecting each firefly to the rod with the shortest possible perpendicular elastic spring; the best rod orientation minimizes the total elastic energy stored in all springs.

Where the analogy breaks down: Physical springs exert mechanical forces that pull the rod according to torque around a pivot, whereas in PCA every spring length is squared (ei2e_i^2) precisely so that orthogonal components decouple cleanly via the Pythagorean theorem across arbitrary dimensions Rd\mathbb{R}^d.

7. Critical Misconceptions and Edge Cases

Common Trap — Using Non-Unit Vectors in x^i=(xi⋅v)v\hat{\mathbf{x}}_i = (\mathbf{x}_i \cdot \mathbf{v})\mathbf{v}: If you use an unnormalized vector such as v=[11]\mathbf{v} = \begin{bmatrix} 1 \\ 1 \end{bmatrix} (where ∥v∥=2\|\mathbf{v}\| = \sqrt{2}), the formula (xi⋅v)v(\mathbf{x}_i \cdot \mathbf{v})\mathbf{v} stretches every shadow by a factor of ∥v∥2=2\|\mathbf{v}\|^2 = 2! For a non-unit vector v\mathbf{v}, you must divide by vTv\mathbf{v}^T\mathbf{v}: x^i=xi⋅vv⋅vv\hat{\mathbf{x}}_i = \frac{\mathbf{x}_i \cdot \mathbf{v}}{\mathbf{v} \cdot \mathbf{v}}\mathbf{v}. Normalizing ∥u∥=1\|\mathbf{u}\|=1 upfront eliminates the denominator.

8. Active Recall Check and Key Takeaways

Quick Check: Test Your Understanding

Question: A centered 2D point is x=[34]\mathbf{x} = \begin{bmatrix} 3 \\ 4 \end{bmatrix}, and our candidate axis is at 45∘45^\circ with unit vector u=[1/21/2]\mathbf{u} = \begin{bmatrix} 1/\sqrt{2} \\ 1/\sqrt{2} \end{bmatrix}. What is the scalar projection zz, the 2D shadow x^\hat{\mathbf{x}}, and the squared orthogonal error e2e^2?

Answer: First, compute the dot product: z=x⋅u=3+42=72z = \mathbf{x} \cdot \mathbf{u} = \frac{3 + 4}{\sqrt{2}} = \frac{7}{\sqrt{2}}. Next, multiply zz by u\mathbf{u} to get the 2D shadow: x^=72[1/21/2]=[3.53.5]\hat{\mathbf{x}} = \frac{7}{\sqrt{2}} \begin{bmatrix} 1/\sqrt{2} \\ 1/\sqrt{2} \end{bmatrix} = \begin{bmatrix} 3.5 \\ 3.5 \end{bmatrix}. Finally, the residual vector is x−x^=[−0.50.5]\mathbf{x} - \hat{\mathbf{x}} = \begin{bmatrix} -0.5 \\ 0.5 \end{bmatrix}, so the squared error is e2=(−0.5)2+0.52=0.5e^2 = (-0.5)^2 + 0.5^2 = 0.5.

  • Mean-centering places the dataset's center of mass at the origin 0\mathbf{0} so linear subspaces capture internal spread rather than distance from the origin.
  • Unit direction vectors (∥u∥=1\|\mathbf{u}\|=1) allow scalar projections to be written simply as zi=uTxiz_i = \mathbf{u}^T\mathbf{x}_i and vector reconstructions as x^i=(uTxi)u\hat{\mathbf{x}}_i = (\mathbf{u}^T\mathbf{x}_i)\mathbf{u}.
  • Orthogonal residuals treat all features symmetrically, distinguishing PCA from vertical least-squares regression.
  • Canonical References: Explore Jonathan Shlens' Tutorial on Principal Component Analysis (arXiv:1404.1100) and the Wikipedia Reference on Principal Component Analysis.

Take a Quiz Based on This Article

Test your understanding with AI-generated questions tailored to this content

Adaptive Learning with SynLearn

Explore this article through guided practice that adapts to your answers

✓Step-by-step concepts & lessons
✓Active recall & adaptive feedback
✓Personalized spaced repetition
pca
dimensionality-reduction
orthogonal-projection
mean-centering
linear-algebra
data-science