2.2.1 · D1Linear & Logistic Regression

Foundations — Simple linear regression model

1,980 words9 min readBack to topic

Before you can derive that line (which the parent note does), you must be fluent in the tiny alphabet of symbols it throws at you. This page defines every single one from zero — plain words first, then a picture, then why the topic can't live without it. Nothing here assumes you've seen algebra beyond "a line has a slope".


What a data point even is

The whole subject starts with paired measurements. You measure two numbers about the same thing and write them together.

Figure — Simple linear regression model

Why the topic needs this. Everything else — the line, the errors, the formulas — is built on top of these dots. If you can plot a dot at horizontal position and height , you already understand the raw material.

Why is horizontal and vertical? Because we chose to be the thing we know and the thing we compute from it. Horizontal = "what I feed in", vertical = "what comes out". This convention never changes in the whole chapter.


The straight line: slope and intercept

A straight line is described by exactly two numbers. Not three, not one — two. Give me those two numbers and I can draw the whole infinite line.

Figure — Simple linear regression model

Slope is a ratio. Move right by (a change in ), the line rises by . Then

The triangle symbol ("delta") just means "the change in". If price rises $20k every time size grows by 1 unit, the slope is . This is exactly the "price per square foot" interpretation the parent note gives.

All cases of slope:

  • : line goes up to the right (bigger → bigger ).
  • : line goes down to the right (bigger → smaller ).
  • : flat line — ignores entirely. The best prediction is just a constant.

Prediction vs. reality: the hat and the residual

Here is the subtlety that trips everyone up. There are two -values at every input.

They almost never match. The gap between them is the star of the whole show:

Figure — Simple linear regression model

Why vertical and not perpendicular? Because we only ever make mistakes in — the thing we predict. The input is given to us for free; we never guess it. So "how wrong were we?" is measured straight up and down.

Why the topic needs residuals. The "best" line is defined as the one that makes these gaps small all together. No residuals, no notion of "best". This is the seed of Ordinary Least Squares in the parent note.

The error term (Greek "epsilon") in the model is the idealised cousin of the residual: it's the built-in randomness of the real world that no straight line could ever capture (measurement noise, a thousand tiny unmeasured causes). The residual is what we actually see; is what we assume exists.


The summation sign: adding across all points

To score a whole line we must combine all the residuals into one number. That needs the sigma symbol.

Worked micro-example. If your residuals are , , then

Why the topic needs it. The loss the parent minimises is . Without we could only talk about one point at a time — but a good line is a compromise across all of them.


The mean: the balance point

Picture the dots' shadows on the horizontal axis; is the point where they'd perfectly balance on a see-saw. Same for vertically. Together is the centre of the whole cloud — and a beautiful fact the parent derives is that the best-fit line always passes through this centre point.


Spread and co-movement: variance and covariance

The slope formula in the parent is . Two ideas hide inside it.

Figure — Simple linear regression model

Squaring and the square root

Two humble operations do heavy lifting.


How it all fits together

Data point (x, y)

Plot on axes

Straight line: slope and intercept

Mean x-bar and y-bar

Variance of x

Covariance of x and y

Prediction y-hat

Residual e = y minus y-hat

Sum with sigma

Square each residual: RSS

Slope formula

Best-fit line = OLS

Evaluate: R-squared and RMSE

Every node here is a symbol you just learned. Follow the arrows and you have reconstructed the entire logic of the parent topic — from a single dot to a fitted, scored model. This same foundation carries you forward into multiple regression, the optimisation view in gradient descent, the assumption checks, and eventually the curved cousin in logistic regression. Squaring residuals is also the seed of the overfitting story.


Equipment checklist

Cover the right side and answer each aloud before moving to the parent derivation.

What do the brackets in mean?
One input paired with one output — a single dot; horizontal, vertical.
What does the subscript do?
It's a name tag: is the -th point's input.
What two numbers fully describe a straight line?
The intercept (launch height) and the slope (climb rate).
What is the slope in words?
How much changes for a 1-unit increase in — rise over run.
What does a hat on signal?
A predicted / estimated value from the line, not a measured one.
What is a residual ?
The vertical gap between the real dot and the line.
Why measure the gap vertically, not perpendicularly?
We only make errors in ; is given, so wrongness is up-and-down.
What does tell you to do?
Plug in through and add all the results.
What is and what picture goes with it?
The mean of all values — the balance point of the cloud along the -axis.
Why square residuals before adding?
To kill signs (so misses can't cancel) and punish big errors harder; also makes calculus work.
What does covariance of measure?
Whether and tend to rise above their means together (positive) or opposite (negative).
Why is slope = covariance ÷ variance?
Dividing out the spread of leaves a clean rise-in- per unit-rise-in-.
What does do in RMSE?
Undoes the squaring so the error returns to 's original units.