Visual walkthrough — Multiple regression
We only assume you can read a graph and multiply numbers. Everything else — vectors, "length", "perpendicular", matrices — we earn as we go.
Step 1 — What are we even looking at? Points and a guess
WHAT. We have a table of observations. Each row is one thing we measured: some inputs (call them 's) and one output we want to predict. Below, imagine just one input so we can draw it flat on paper — the whole story generalises later.
WHY start with one dot at a time. Before any algebra, the object we minimise is a gap: the vertical distance between a real data point and wherever our guessing-line sits underneath it. If you cannot picture that gap, no formula will mean anything.
PICTURE. The amber dots are the data. The cyan line is one guess at the trend. The dashed white segments are the vertical gaps — how wrong the guess is at each point.
Step 2 — Why we square the gaps
WHAT. We add up all the gaps to score a line. But we square each gap first: our score is Here is just "add them all up", and is how many data points we have.
WHY square, not just add? Two problems with raw gaps. (1) A point above and one below would cancel to — a terrible line would score "perfect". Squaring kills the sign since a square is never negative. (2) Squaring bends the score into a smooth bowl, so calculus can find its bottom exactly (Step 6). Absolute value also kills signs but has a sharp corner — no clean formula.
PICTURE. Each dashed gap becomes a literal square (amber). The total shaded area is the score . Our whole job: slide and tilt the line until the total amber area is as small as possible.
Step 3 — Stacking the data into arrows (vectors)
WHAT. Instead of separate numbers, put all the into one tall list and treat that list as a single arrow in a high-dimensional space: The bold is now one point living in -dimensional space (one axis per data point).
WHY do this bizarre thing? Because "sum of squared gaps" secretly is a squared length. If two arrows have a gap , the squared length of that gap arrow is exactly — the same shape as our score. So minimising becomes: find the arrow closest to . Distance is something we have strong geometric intuition for.
PICTURE. Left: three numbers . Right: the same three numbers read as coordinates of one arrow in 3-D space. Same data, new eyes.
With this, our score is reborn:
Step 4 — Which arrows can our model reach? The column space
WHAT. Our prediction is . Here is the table of inputs (with a leading column of 1's for the intercept), and is the list of coefficients we get to choose. Multiplying means: It is a weighted blend of the columns of , with the 's as the mixing weights.
WHY this matters. As we dial the 's over all possible values, sweeps out every blend of those columns — and no more. That set of reachable arrows is a flat sheet (a plane, in general a hyperplane) passing through the origin. Our data arrow almost never lies on this sheet (real data is noisy). So we cannot hit — we can only get as close as the sheet allows.
PICTURE. Two input columns span a tilted cyan plane (the column space). The data arrow (amber) juts off the plane. Every prediction we can make lives on the plane.
Step 5 — The closest point is the foot of the perpendicular
WHAT. On the flat sheet, which point is nearest to ? Drop straight down onto the sheet. The landing spot — the foot of the perpendicular — is the closest reachable point.
WHY perpendicular, not slanted? Slide the landing point a hair in any direction along the sheet. If the connecting arrow were tilted (not perpendicular), moving toward its tilt would shorten the gap — so you weren't at the minimum yet. Only when the gap arrow stands exactly perpendicular to the sheet can no sideways nudge help. That is the geometric meaning of "least squares".
PICTURE. The amber residual arrow meets the plane at a clean right angle (little white square). Any other point on the plane (grey) is farther from — its dashed connector is longer.
Step 6 — Turning "perpendicular" into the normal equations
WHAT. "The residual is perpendicular to the sheet" means it is perpendicular to every column of (the columns spread out the sheet). Two arrows are perpendicular when their dot product is zero. Bundling all those "" statements together:
Term by term:
- — the flipped table; row of it is column of . Multiplying by it computes the dot product of each predictor column with whatever follows.
- — the residual arrow (data minus prediction).
- — a column of zeros: every predictor is perpendicular to the residual.
WHY dot product? The dot product measures overlap; it is zero exactly when the arrows meet at . It is the perfect tool to state "no leftover overlap between residual and predictors".
PICTURE. Each predictor column (cyan) forms a right angle with the residual (amber). The dot product of each with the residual reads zero.
Multiply the bracket out — distribute across the subtraction:
Step 7 — Solving for the coefficients
WHAT. To isolate , undo the multiplication by . Undoing a matrix multiply is done by its inverse (the matrix version of "divide"). Apply it to both sides:
WHY an inverse and not real division? You cannot divide by a matrix. The inverse is defined so that (the identity, the "do-nothing" matrix), which cancels cleanly on the left and leaves alone. See Matrix Inverse.
PICTURE. A flow: the data enters, gets dotted against predictors (), then rescaled by , and out comes the weight list — which lands us on the foot of the perpendicular.
Step 8 — The degenerate case: when the inverse does not exist
WHAT. Step 7 quietly assumed exists. It fails to exist when two (or more) predictor columns point the same way — one is a copy or a scaled sum of others. This is perfect collinearity.
WHY it breaks — geometrically. If two columns are parallel, they no longer spread out a full plane; the "sheet" collapses to a lower-dimensional line. Now infinitely many weight-blends land on the same prediction arrow — you can add to one and subtract from its twin with zero visible change. There is no unique answer, so no inverse.
PICTURE. Left (healthy): two columns fan out and pin down one plane; the foot of the perpendicular is unique. Right (collinear): the columns overlap into a single line; the projection point is unpinned — it can slide, so is not unique.
Recall Why is
always at least positive semidefinite? For any weight vector , — it is a squared length, which can never be negative. It is strictly positive (hence invertible) exactly when the columns of are independent (no collinearity).
The one-picture summary
Everything above collapses into a single diagram: the data arrow , the flat sheet of reachable predictions (column space of ), the perpendicular drop giving , and the residual standing at a right angle — which is the normal equation , which is the boxed estimator.
Recall Feynman: the whole walkthrough in plain words
We had a cloud of data and wanted the best flat ramp through it. First we asked "how wrong is a ramp?" — measure the up-and-down gaps and square them so pluses and minuses can't cancel. Then a trick: pile all the outputs into one giant arrow, so "smallest total squared gap" becomes "which reachable arrow is closest to my data arrow?". The ramp can only reach a flat sheet of arrows (blends of the input columns), and the closest spot on any flat sheet is found by dropping straight down — a perpendicular. Writing "the leftover gap is perpendicular to every input" with dot products gives ; undoing the matrix multiply gives . And if two inputs secretly say the same thing, the sheet collapses, the drop-point can slide, and there's no single answer — that's collinearity, and it's why we watch the VIF.