2.2.2 · D1Linear & Logistic Regression

Foundations — Multiple linear regression

3,109 words14 min readBack to topic

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.


1. A "feature" and a "target" — the raw ingredients

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.

Figure — Multiple linear regression

Notation for features. We write the features as .

  • The letter means "a feature value".
  • The little number below (the subscript) says which feature: is size, is bedrooms, and so on.
  • is simply how many features we have. If we track size, bedrooms, age, then .

The target is written .


2. Many houses at once — the superscript

We rarely have one house. We have a whole list. To point at a specific house we add a superscript in brackets:

The letter means how many examples (houses) we have. So we have houses, each described by features.

Recall

What does the little number below (subscript) tell you? ::: Which feature it is (which column). What does the bracketed number above tell you? ::: Which example/row it is (which house). If we have 100 houses and track size, bedrooms, age, what are and ? ::: , .


3. The prediction formula — weighted addition, spelled out

Here is the parent note's central line:

Let us earn every symbol.

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.

Figure — Multiple linear regression
Recall

In , what is the intercept? ::: . What does mean in words? ::: Each extra square foot adds $0.2k to the predicted price, holding bedrooms fixed.


4. From "a line" to "a hyperplane"

With one feature, is a straight line on a 2D graph. With two features it becomes a flat plane floating above the 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.

Figure — Multiple linear regression

5. Vectors and matrices — a filing cabinet for numbers

Writing the formula out for every house is exhausting. Instead we stack numbers into grids.

The parent's data matrix looks like:

Now we can name the whole bundle of weights as one object.


6. The dot product — one prediction in one stroke

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.

From dot product to full matrix multiplication. Multiplying a matrix by a vector is just "do this dot product once per row":

So produces one predicted number per house, all at once. One symbol replaces separate formulas.

Recall

Row dotted with weights — what do you get? ::: . An matrix times an vector has what shape? ::: — one prediction per row. What does always equal, and why? ::: — it is the 0-th column, the invented constant feature that carries the intercept.


7. The transpose — flipping a grid on its side

The parent note writes (read "X transpose").

Figure — Multiple linear regression

8. Error, squaring, and "best fit"

Our guess won't match the true perfectly. For house , the gap is the error (or residual), written :

The big (Greek capital sigma) just means "add these up for every house, from house to house ". The turns the total into an average. We write because the score depends on which weights we pick.


9. The matrix inverse — "undoing" a multiplication

Before we can read the Normal Equation we need one last symbol: the little .


10. How it all connects

Features x1..xn and target y

Weighted addition = prediction y-hat

Vectors and matrices X, beta, y

Dot product

X times beta = all predictions

Transpose X-top

X-top times X

Error = y minus y-hat

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.


Equipment checklist

Test yourself — reveal only after answering.

What does mean and how is it different from ?
is the model's guess; 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 , what do the and the each mean?
= which feature (column); = which example/house (row).
What does equal, and what is it for?
It equals for every house; it is the constant feature that carries the intercept .
What do and represent?
is the baseline (intercept); each is the weight for feature .
What is the bold , and how many entries does it have?
The column vector stacking all weights; it has entries (intercept plus one per feature).
What is the shape of the data matrix ?
rows (houses), columns (features plus the 1's column).
What does the entry mean?
The number in row , column of .
Why is there a column of 1's in ?
So the intercept 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 ( times ); result is .
What does the transpose do?
Flips rows into columns and columns into rows.
What does the inverse do, and what is ?
It undoes (matrix "division"); .
Name two situations where has no inverse.
Fewer examples than weights (), 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 instruct you to do?
Add the following quantity for every example from to .
What does "best fit" mean numerically?
The weights that make the MSE cost as small as possible.
Write the Normal Equation from memory.
.