This page is the ground floor of the parent topic. Before we can appreciate why θ=(XTX)−1XTy is beautiful, we must earn every single symbol in it. We build from a single dot on paper up to the full matrix machine. If you can already read every line of the Equipment checklist at the bottom, skip ahead.
Imagine points scattered on graph paper. Each dot is one training example: something we measured (an input) paired with an outcome we want to predict (an output). Our whole job is to lay a straight ruler through them so it passes as close as possible to all the dots at once.
Look at the amber ruler above. The vertical cyan gaps between each dot and the ruler are the errors. "Best ruler" will mean: the ruler that makes those gaps, taken all together, as small as possible. Every symbol below exists to make that sentence precise.
Picture a spreadsheet. The subscript picks a column (which measured quantity), the superscript(i) picks a row (which data point).
Why the topic needs it: with m examples and n features, we cannot write out every value. Subscripts and superscripts let us name any cell with two little labels.
Picture: a table with m rows and n input columns, plus one final answer column y.
Why the topic needs it: the parent's cost function sums ∑i=1m — that "1 to m" is exactly "loop over every dot." You cannot read that sum without knowing m.
Two pictures of the same object: an arrow from the origin (left), and a stack of numbers (right). Both are [32]. The arrow view helps for geometry (length, angle, perpendicular); the stack view helps for computation.
Why the topic needs it:y (all the true answers) and θ (all the knobs) are vectors. Stacking them lets one formula act on the whole dataset at once.
Picture: the dot product slides one vector along the other, multiplying overlapping entries — a single "weighted total." That total is the height of the ruler above that input point.
Why x0=1? Notice θ0 needs a partner x0 so the pattern stays uniform. We invent a fake feature x0=1 for every example. Then θ0x0=θ0, giving us the intercept for free while keeping one clean formula.
The 2m1 is cosmetic: m1 averages over dataset size, and the 21 will cancel a factor of 2 when we differentiate. Neither changes where the minimum is.
Why the topic needs it: the normal equation is the exact place where J bottoms out. J is the thing we minimize.
The figure shows the shapes clicking together. Multiplying X (m×(n+1)) by θ ((n+1)×1) gives Xθ: a single column of m predictions — one for every dot, all at once. Matrix multiply is just "do the dot product of each row with the vector."
Because we squared the errors, J plotted against θ is a bowl (a paraboloid) — the amber surface above. At the very bottom of a smooth bowl the ground is perfectly flat, so every slope is zero. That is why we write:
∇θJ=0
"Set the gradient to zero" means "find the flat spot," and for a bowl there's exactly one flat spot: the minimum. Solving that flatness condition is the normal equation.
Contrast:Gradient Descent walks downhill along −∇J in many small steps; the normal equation jumps straight to where ∇J=0 in one algebra move.
Cover the right side; can you answer each before revealing?
What does m count?
The number of training examples (rows of data / dots).
What does n count?
The number of features (input columns), not counting the added 1's column.
What is the difference between x(2) and x2?
x(2) (parentheses) is the second example; x2 is xsquared.
What does a bold lowercase symbol like y mean?
A vector — an ordered column of numbers.
In one sentence, what is a dot product?
Multiply matching entries of two vectors and add them all up.
Why is there a fake feature x0=1?
So θ0x0=θ0 gives the intercept while keeping one uniform dot-product formula.
Why do we square the errors in J?
To stop positive and negative gaps cancelling and to make a smooth single-minimum bowl.
What is the shape of Xθ?
A column vector of m predictions, one per example.
What does ∇θJ=0 mean geometrically?
We are at the flat bottom of the cost bowl — the minimum.
When does (XTX)−1 fail to exist?
When X is rank-deficient (a feature is a linear combination of others), making XTX singular.
What does the transpose XT do?
Flips rows into columns; an m×k matrix becomes k×m.
Recall Self-check: can you read the whole formula aloud?
θ=(XTX)−1XTy — "theta equals: transpose-X times X, all inverted, times transpose-X, times the answer vector y." If that sentence made sense, you're ready for the parent note.