| father | mother | child | gender |
|---|---|---|---|
| 78.5 | 67.0 | 73.2 | male |
| 75.5 | 66.5 | 73.5 | male |
| 75.0 | 64.0 | 71.0 | male |
| 75.0 | 64.0 | 70.5 | male |
| 75.0 | 58.5 | 72.0 | male |
| 74.0 | 68.0 | 69.5 | female |
Projection onto Feature Space
In Part 1, we explored data through:
Part 2 takes a different approach: the geometry of linear algebra.
Core insight
Least-squares regression is orthogonal projection onto feature space.
Linear algebra provides:
This chapter: Regression as projection
Next chapters: PCA and LDA as finding optimal subspaces
| Perspective | Focus | Visualization |
|---|---|---|
| Row | Observations as points | Scatter plots in feature space |
| Column | Features as vectors | Vectors in observation space |
Most visualizations use the row perspective.
Most linear algebra uses the column perspective.
Understanding both is essential.
In 1885, Francis Galton studied heights of parents and children.
| father | mother | child | gender |
|---|---|---|---|
| 78.5 | 67.0 | 73.2 | male |
| 75.5 | 66.5 | 73.5 | male |
| 75.0 | 64.0 | 71.0 | male |
| 75.0 | 64.0 | 70.5 | male |
| 75.0 | 58.5 | 72.0 | male |
| 74.0 | 68.0 | 69.5 | female |
Goal: Predict child’s height from parents’ heights.
Figure 1: Family heights: sons (blue), daughters (red)
In an earlier chapter, we regressed son’s height on father’s height → regression line
Now: regress son’s height on both parents’ heights → regression plane
\[ \hat{s} = \beta_0 + \beta_m \cdot m + \beta_f \cdot f \]
where \(m\) = mother’s height, \(f\) = father’s height
Figure 2: Regression plane with residual segments
| Term | Coefficient |
|---|---|
| Intercept | 19.94 |
| Mother | 0.28 |
| Father | 0.47 |
Interpretation:
\[ y_\bullet = X_{\bullet,\bullet} \; \beta_\bullet + \epsilon_\bullet \]
| Symbol | Name | Dimension |
|---|---|---|
| \(y_\bullet\) | Response (target) | \(n \times 1\) |
| \(X_{\bullet,\bullet}\) | Feature matrix | \(n \times d\) |
| \(\beta_\bullet\) | Coefficients | \(d \times 1\) |
| \(\epsilon_\bullet\) | Residuals | \(n \times 1\) |
The columns of \(X\) span a subspace called feature space:
\[ \text{col}(X) = \text{span}(x_{\bullet,1}, \ldots, x_{\bullet,d}) \]
Any prediction \(\hat{y} = X\beta\) is a linear combination of feature vectors:
\[ \hat{y}_\bullet = \beta_1 x_{\bullet,1} + \cdots + \beta_d x_{\bullet,d} \]
So \(\hat{y}\) must lie in \(\text{col}(X)\).
Given \(y_\bullet\) and \(X_{\bullet,\bullet}\):
Find \(\beta_\bullet\) that minimizes \(\|\epsilon_\bullet\|\)
This is the least-squares problem.
Geometric interpretation
Find the point in feature space closest to \(y\).
The Euclidean norm (length) of vector \(v\):
\[ \|v_\bullet\|_2 = \sqrt{\sum_{\nu=1}^{n} v_\nu^2} \]
Minimizing \(\|\epsilon\|^2\) is the least-squares criterion:
\[ \min_\beta \sum_{\nu=1}^{n} (y_\nu - \hat{y}_\nu)^2 \]
The inner product of vectors \(v\) and \(w\):
\[ \langle v, w \rangle = v^\top w = \sum_{\nu=1}^{n} v_\nu w_\nu \]
Key properties:
Inner products connect to covariance and correlation.
Theorem: The least-squares solution \(\hat{y}\) is the orthogonal projection of \(y\) onto \(\text{col}(X)\).
The residual \(\epsilon = y - \hat{y}\) is perpendicular to feature space.
Intuition: If \(\epsilon\) had any component along \(\text{col}(X)\), we could reduce its length by adjusting \(\hat{y}\).
Mathematically: \(\epsilon \perp x_{\bullet,j}\) for every feature vector \(j\).
The regression plane \(\hat{s} = \beta_0 + \beta_m m + \beta_f f\) doesn’t pass through the origin.
Problem: It’s not a proper subspace (subspaces must contain the origin).
Solution: Center the data!
Replace each value with its deviation from the mean:
\[ \dot{v}_\nu = v_\nu - \bar{v} \]
After centering:
\[ \dot{v}_\bullet = C \; v_\bullet \]
where
\[ C = I - \frac{1}{n} \mathbf{1}\mathbf{1}^\top \]
\(C\) is itself a projection matrix—it projects onto the subspace orthogonal to the constant vector.
To minimize \(\|\epsilon\|^2 = \|y - X\beta\|^2\):
Take derivative with respect to \(\beta\), set to zero:
\[ X^\top X \; \hat{\beta} = X^\top y \]
These are the normal equations.
Solving for \(\hat{\beta}\):
\[ \hat{\beta} = (X^\top X)^{-1} X^\top y \]
The predicted values:
\[ \hat{y} = X \hat{\beta} = \underbrace{X(X^\top X)^{-1} X^\top}_{P} y \]
Matrix \(P\) is the projection matrix (or “hat matrix”).
The projection matrix \(P = X(X^\top X)^{-1}X^\top\) satisfies:
Idempotent: \(P^2 = P\)
(Projecting twice = projecting once)
Symmetric: \(P^\top = P\)
(Makes it an orthogonal projection)
Complementary: \((I - P)\) projects onto the orthogonal complement
Since \(\hat{y} = Py\) and \(\epsilon = (I-P)y\):
\[ \hat{y}^\top \epsilon = y^\top P^\top (I-P) y = y^\top (P - P^2) y = 0 \]
Key result
Predicted values and residuals are orthogonal.
| View | Space | Dimension |
|---|---|---|
| Row | Observations as points in \(\mathbb{R}^d\) | \(d\)-dimensional |
| Column | Features as vectors in \(\mathbb{R}^n\) | \(n\)-dimensional |
Figure 4: Row view: points in feature space, plane fits through them
In \(n\)-dimensional space (one dimension per observation):
This is where the linear algebra happens!
| Operation | Row View | Column View |
|---|---|---|
| Fit model | Find plane minimizing vertical distances | Project \(y\) onto \(\text{col}(X)\) |
| Residual | Vertical distance to plane | \(y - \hat{y}\) |
| Prediction | Point on plane | Vector in \(\text{col}(X)\) |
The projection perspective is foundational for:
Regularization: Ridge regression modifies the projection \[\hat{\beta}_{\text{ridge}} = (X^\top X + \lambda I)^{-1} X^\top y\]
Dimension reduction: PCA finds the “best” low-dimensional subspace
Kernel methods: Project into implicit high-dimensional feature spaces
Neural networks: Each layer performs a linear transformation (projection) followed by a nonlinearity
For centered data:
\[ \text{Cov}(x, y) = \frac{1}{n-1} \langle \dot{x}, \dot{y} \rangle \]
Correlation is the cosine of the angle between centered vectors:
\[ r = \frac{\langle \dot{x}, \dot{y} \rangle}{\|\dot{x}\| \; \|\dot{y}\|} \]
This connects regression to the correlation coefficient from Part 1!
Row vs Column: Two complementary views of the same data
Least squares = Projection: \(\hat{y}\) is the orthogonal projection of \(y\) onto feature space
Centering matters: Makes the geometry cleaner (proper subspaces)
P is special: Symmetric, idempotent → orthogonal projection
Residuals ⊥ Features: The defining property of least-squares
Generic linear model: \[y = X\beta + \epsilon\]
Normal equations: \[X^\top X \hat{\beta} = X^\top y\]
Projection matrix: \[P = X(X^\top X)^{-1}X^\top\]
Predicted values: \[\hat{y} = Py\]
Let \(y = (3, 1, 2)^\top\) and \(x = (1, 2, 2)^\top\).
For the Galton height regression:
For centered vectors \(\dot{x}\) and \(\dot{y}\):
Statistics by Freedman, Pisani, Purves — intuitive treatment of regression
Linear Algebra and Its Applications by Strang — definitive LA text
Introduction to Statistical Learning (ISLR2) — regression in ML context
The Elements of Statistical Learning — advanced treatment