Orthogonal Projections as Conditional Expectation

Formal

Suppose we want to predict a random variable YY using information from another random variable (or vector of variables) XX. We seek a function g(X)g(X) that minimizes the Mean Squared Error (MSE):

MSE=E[(Yg(X))2](1)\text{MSE} = \mathbb{E}\left[(Y - g(X))^2\right] \tag{1}

The mathematical theorem states that the unique function g(X)g^*(X) that minimizes this MSE is the conditional expectation:

g(X)=E[YX](2)g^*(X) = \mathbb{E}[Y \mid X] \tag{2}
The Geometric Interpretation (Orthogonality)

Because random variables form a Hilbert space (see Geometry of Random Variables), we can view this purely geometrically.

  • YY is a vector in the full space.
  • The set of all possible functions of XX forms a subspace.
  • The error of our prediction is the vector e=Yg(X)\mathbf{e} = Y - g(X).

To minimize the length (norm) of the error vector e2\|\mathbf{e}\|^2, the error must be orthogonal to the subspace of XX. This is the Orthogonality Principle:

YE[YX],h(X)=0for any function h(3)\langle Y - \mathbb{E}[Y \mid X], h(X) \rangle = 0 \quad \text{for any function } h \tag{3}

Therefore, the conditional expectation E[YX]\mathbb{E}[Y \mid X] is exactly the orthogonal projection of YY onto the subspace spanned by XX.

Intuition

Imagine you are a shadow on a 2D floor (the subspace XX), trying to get as close as possible to a bird flying in the 3D air above you (the target variable YY).

If you stand directly beneath the bird, the distance between you and the bird is a straight vertical line. That vertical line is orthogonal (perpendicular) to the floor. Any other position on the floor would result in a longer diagonal distance.

Linear Regression is just an algorithm that finds the “shadow” of YY on the “floor” of XX.

ML Applications
  • Linear Regression (OLS) — Ordinary Least Squares is the most direct application. The formula β^=(XTX)1XTY\hat{\beta} = (X^T X)^{-1} X^T Y is literally the projection matrix projecting the vector YY onto the column space of XX.
  • Why we use MSE — When we train a neural network with an MSE loss function, we are explicitly asking the network to approximate the conditional expectation E[YX]\mathbb{E}[Y \mid X]. If we used MAE (L1 loss) instead, the network would approximate the conditional median.
  • The Bias-Variance TradeoffE[YX]\mathbb{E}[Y \mid X] represents the theoretical limit of how good a model can be (the irreducible error). Our model f(x)f(x) is just trying to approximate that projection.
Connections
  • #type/bridge
  • #probability
  • #linear-algebra
  • #regression