Intuition The One Core Idea
Multiple linear regression is just weighted addition : take several measurements about a thing, multiply each by a number saying "how much this matters", add them up, and you get a prediction. Everything else — matrices, transposes, the Normal Equation — is bookkeeping that lets us do this weighted addition for thousands of things at once and find the best weights automatically.
This page assumes you have seen nothing . We will meet every symbol that appears on the parent note one at a time, draw what it means, and only then use it. If you can add and multiply, you can finish this page.
Definition Feature and target
A feature is one measurable fact about a thing (a house's size, its bedroom count). The target is the single number we want to predict about that same thing (its price).
Picture a house. We can write down facts about it — size, bedrooms, age. Each fact is a feature . The thing we don't know yet, the price , is the target .
Intuition Why more than one feature?
Price does not depend on size alone . A tiny 3-bedroom flat and a huge studio cost differently. Each extra feature is a new "reason" the price could go up or down. Using many features is why this is called Multiple linear regression — compare Simple Linear Regression , which uses just one.
Notation for features. We write the features as x 1 , x 2 , … , x n .
The letter x means "a feature value".
The little number below (the subscript ) says which feature: x 1 is size, x 2 is bedrooms, and so on.
n is simply how many features we have . If we track size, bedrooms, age, then n = 3 .
The target is written y .
We rarely have one house. We have a whole list. To point at a specific house we add a superscript in brackets:
x 2 ( 3 ) = feature 2 (bedrooms) of house number 3
Common mistake Superscript is NOT a power
x 2 ( 3 ) does not mean "x 2 cubed". The brackets are the giveaway: ( 3 ) is a label meaning "the 3rd example", while x 3 (no brackets) would be a power. We use brackets exactly to avoid this confusion.
The letter m means how many examples (houses) we have . So we have m houses, each described by n features.
Recall
What does the little number below x (subscript) tell you? ::: Which feature it is (which column).
What does the bracketed number above x tell you? ::: Which example/row it is (which house).
If we have 100 houses and track size, bedrooms, age, what are m and n ? ::: m = 100 , n = 3 .
Here is the parent note's central line:
y ^ = β 0 + β 1 x 1 + β 2 x 2 + ⋯ + β n x n
Let us earn every symbol.
y ^
y ^ (read "y-hat") is our guess of the target. Plain y is the true value we know from data; y ^ is what the model outputs . The hat means "estimated".
β 1 , … , β n
β is the Greek letter "beta". Each β i is a coefficient (a weight): a number saying how strongly feature x i pushes the prediction. Big positive β → this feature raises the prediction a lot; negative → it lowers it.
Definition The intercept:
β 0
β 0 is the intercept (or bias): the prediction you'd make if every feature were zero. It sets the baseline height before any feature adjusts it.
So the formula reads, in plain English:
**prediction = baseline + (weight₁ × feature₁) + (weight₂ × feature₂) + … **
That's it. It's weighted addition. The picture below shows each feature contributing a slice.
Recall
In y ^ = − 150 + 0.2 x 1 + 50 x 2 , what is the intercept? ::: − 150 .
What does β 1 = 0.2 mean in words? ::: Each extra square foot adds $0.2k to the predicted price, holding bedrooms fixed.
With one feature, y ^ = β 0 + β 1 x 1 is a straight line on a 2D graph. With two features it becomes a flat plane floating above the ( x 1 , x 2 ) floor. With more features we can't draw it, but it's the same flat shape in more dimensions — mathematicians call any such flat sheet a hyperplane .
Intuition Why "linear" and why "flat"?
"Linear" means each feature enters only by being multiplied by a constant and added — no squaring, no multiplying features together. That restriction is exactly what keeps the surface flat. If you want curves, you bend features first with Polynomial Regression ; the fitting machinery here stays the same.
Writing the formula out for every house is exhausting. Instead we stack numbers into grids.
A vector is a single column (or row) of numbers — one number stacked above another. We write it in bold: y . Picture a single tall column of prices, one per house.
A matrix is a full grid — rows and columns of numbers, bold capital: X . Picture a spreadsheet: one row per house , one column per feature . We describe its size as rows × columns .
The parent's data matrix looks like:
X = 1 1 ⋮ 1 x 1 ( 1 ) x 1 ( 2 ) ⋮ x 1 ( m ) ⋯ ⋯ ⋱ ⋯ x n ( 1 ) x n ( 2 ) ⋮ x n ( m )
X
X has m rows (one per house) and n + 1 columns (one per feature, plus one for the leading column of 1's). So X is an ==m × ( n + 1 ) == matrix. With 3 houses and 2 features that is a 3 × 3 grid.
Intuition Why the column of 1's?
Look at the prediction: β 0 has no feature multiplying it. To make it fit the same pattern as the others, we invent a fake feature that is always 1 . Then β 0 × 1 = β 0 — the intercept becomes "just another weight", and the whole formula collapses into one clean multiplication. That extra column is bookkeeping, nothing deeper.
Definition Naming the 0-th column:
x 0 ( i ) = 1
Because that invented column sits before x 1 , we give it index 0 and call it x 0 . It is defined to be 1 for every house: x 0 ( i ) = 1 for all i . So a full feature row is ( x 0 ( i ) , x 1 ( i ) , … , x n ( i ) ) = ( 1 , x 1 ( i ) , … , x n ( i ) ) . That is why counting runs from 0 : column 0 is the constant 1's feature that carries the intercept β 0 .
Now we can name the whole bundle of weights as one object.
Definition The weight vector:
β
β (bold "beta") is the single column vector that stacks all the weights together — intercept first, then one per feature:
β = β 0 β 1 ⋮ β n
It has n + 1 entries — one to match every column of X . Bold means "the whole stack"; plain β i means "one entry inside it".
To predict for one house, take its row of features and its matching weights, multiply matching pairs, and add. That operation is the dot product .
Intuition Why a dot product and not something fancier?
We chose it precisely because it equals weighted addition. It is the smallest operation that "combine each feature with its weight and total them" — no more, no less. Nothing else does that job.
From dot product to full matrix multiplication. Multiplying a matrix by a vector is just "do this dot product once per row":
Definition Reading a matrix entry:
X ik
X ik means the single number sitting in row i , column k of the grid X — first index picks the row (which house), second index picks the column (which feature). For example X i 0 is house i 's entry in column 0 , which we just defined to always equal 1 .
Intuition The shape-matching rule in general
To multiply grid A (size p × q ) by grid B (size q × r ), their touching sizes must agree — the q on the right of A must equal the q on the left of B . Each entry of the result is a dot product of one row of A with one column of B . The result has size p × r . This one rule covers X β and X ⊤ X below.
So y ^ = X β produces one predicted number per house, all at once. One symbol replaces m separate formulas.
Recall
Row ( 1 , 1600 , 3 ) dotted with weights ( − 150 , 0.2 , 50 ) — what do you get? ::: − 150 + 0.2 ⋅ 1600 + 50 ⋅ 3 = 320 .
An m × ( n + 1 ) matrix times an ( n + 1 ) × 1 vector has what shape? ::: m × 1 — one prediction per row.
What does X i 0 always equal, and why? ::: 1 — it is the 0-th column, the invented constant feature that carries the intercept.
The parent note writes X ⊤ (read "X transpose").
The transpose X ⊤ turns rows into columns and columns into rows — like tipping the spreadsheet onto its side. If X is m × ( n + 1 ) ("houses down, features across"), then X ⊤ is ( n + 1 ) × m ("features down, houses across").
Intuition Why do we ever need it?
To multiply two grids their touching sizes must line up (Section 6). Flipping one with ⊤ is the trick that lines them up, so that X ⊤ X — an ( n + 1 ) × m times an m × ( n + 1 ) , giving an ( n + 1 ) × ( n + 1 ) grid — can pair every feature against every other feature. That is exactly the "how do features correlate" information the Normal Equation needs.
Our guess y ^ won't match the true y perfectly. For house i , the gap is the error (or residual), written e ( i ) :
e ( i ) = y ( i ) − y ^ ( i )
Intuition Why square the error?
Some errors are positive (guessed too low), some negative (too high). If we just added them they'd cancel and hide the mistakes. Squaring makes every error positive and punishes big misses far more than small ones. Adding up all these squares gives one "badness score" — the Mean Squared Error (MSE). "Best fit" means the weights that make this score as small as possible.
J ( β ) = m 1 ∑ i = 1 m ( e ( i ) ) 2 = m 1 ∑ i = 1 m ( y ( i ) − y ^ ( i ) ) 2
The big ∑ (Greek capital sigma) just means "add these up for every house, from house 1 to house m ". The m 1 turns the total into an average. We write J ( β ) because the score depends on which weights β we pick.
Intuition Two paths to the best weights
There are two ways to reach the smallest J : solve it in one shot with the Normal Equation (algebra), or creep downhill step-by-step with Gradient Descent (when the algebra is too big or breaks). Both aim at the same lowest point. When features have very different scales, that downhill path behaves badly unless you use Feature Scaling first.
Before we can read the Normal Equation we need one last symbol: the little − 1 .
Definition The identity matrix
I
The identity matrix I is the matrix version of the number 1 : it has 1 's down its diagonal and 0 's everywhere else. Multiplying anything by I leaves it unchanged, just as multiplying a number by 1 does.
A − 1
For an ordinary number, "divide by 3 " is the same as "multiply by 3 1 ", and 3 × 3 1 = 1 . The inverse A − 1 of a square matrix A plays that same role: it is the matrix that undoes A , so that A − 1 A = I . Matrices have no "÷" symbol, so multiplying by an inverse is how we "divide" — that is exactly why the Normal Equation multiplies by ( X ⊤ X ) − 1 to peel it off the left of β .
Intuition Not every matrix can be inverted
Some numbers can't be undone by multiplication: there is no way to "undo times 0 ", because nothing times 0 gives back 1 . Matrices have the same trap. A singular (non-invertible) matrix is the matrix version of 0 — no inverse exists. When X ⊤ X is singular, the clean formula below simply has no answer to compute.
X ⊤ X has NO inverse
When does the formula break? X ⊤ X is singular (has no inverse) in two everyday situations:
Too few houses: fewer examples than weights, m < n + 1 . There isn't enough data to pin down every weight, so infinitely many weight sets fit equally — the formula can't pick one.
Redundant features (collinearity): one feature is an exact recipe of others, e.g. x 3 = 2 x 1 + x 2 , or "size in sq ft" and "size in sq m" as two columns. The duplicate carries no new information, so a column of X is a copy of others — again no unique answer.
What to do instead:
Drop the redundant/duplicated feature (inspect the correlation matrix).
Add a small nudge to the diagonal so it becomes invertible again — that is exactly Ridge Regression .
Skip the inverse entirely and walk downhill with Gradient Descent , which still works when X ⊤ X is singular.
Having many redundant or noisy features also invites Overfitting , a separate danger covered later.
Features x1..xn and target y
Weighted addition = prediction y-hat
Vectors and matrices X, beta, y
X times beta = all predictions
Square and average = MSE cost J
Matrix inverse and identity
Normal Equation solves for beta
Multiple Linear Regression
Each box on the left is something we built from zero on this page; together they feed the topic in the final box. Later ideas — Ridge Regression for when the algebra breaks, R-squared and Adjusted R-squared for scoring the fit, and Overfitting for its dangers — all sit on top of these foundations.
Test yourself — reveal only after answering.
What does y ^ mean and how is it different from y ? y ^ is the model's guess ; y is the true value from data.
What is a feature? A target? A feature is one measured fact about a thing; the target is the number we want to predict.
In x 3 ( 7 ) , what do the 3 and the ( 7 ) each mean? 3 = which feature (column); ( 7 ) = which example/house (row).
What does x 0 ( i ) equal, and what is it for? It equals 1 for every house; it is the constant feature that carries the intercept β 0 .
What do β 0 and β i represent? β 0 is the baseline (intercept); each β i is the weight for feature i .
What is the bold β , and how many entries does it have? The column vector stacking all weights; it has n + 1 entries (intercept plus one per feature).
What is the shape of the data matrix X ? m × ( n + 1 ) — m rows (houses), n + 1 columns (features plus the 1's column).
What does the entry X ik mean? The number in row i , column k of X .
Why is there a column of 1's in X ? So the intercept β 0 becomes just another weight in the dot product.
What is a dot product in one sentence? Multiply matching pairs of numbers, then add them all.
When can two matrices be multiplied, and what shape results? When the touching sizes match (p × q times q × r ); result is p × r .
What does the transpose X ⊤ do? Flips rows into columns and columns into rows.
What does the inverse A − 1 do, and what is A − 1 A ? It undoes A (matrix "division"); A − 1 A = I .
Name two situations where X ⊤ X has no inverse. Fewer examples than weights (m < n + 1 ), or redundant/collinear features.
Why do we square the errors before adding them? So positives and negatives don't cancel, and big misses are punished more.
What does ∑ i = 1 m instruct you to do? Add the following quantity for every example from 1 to m .
What does "best fit" mean numerically? The weights β that make the MSE cost J as small as possible.
Write the Normal Equation from memory. β = ( X ⊤ X ) − 1 X ⊤ y .