A New Kind of Question
Our first example was cat-or-dog: pick a category. But a huge share of real problems ask for a number instead:
- How much will this house sell for?
- How many views will this video get?
- What temperature will it be tomorrow?
Predicting a number is called regression. Let’s use a friendly example the whole way through: predict a house’s price from its size.
Look at the Data First
Imagine you collect real sales. Each house becomes a dot: its size along the bottom, its price up the side.
The dots don’t line up perfectly, but the trend is obvious, bigger houses cost more. The cloud slopes upward.
Your job is to draw a line through that cloud. Once you have it, you can predict the price of any house, even ones you’ve never seen.
The Model Is Just a Line
A straight line is described by two numbers:
- is the slope: how much the price climbs for each extra unit of size. We call it a weight.
- is the intercept: the base price where the line starts. We call it a bias.
That’s the entire model. Those two numbers, and , are the “pile of numbers” from note 1. A house-price model is literally just a good and a good .
And making a prediction is dead simple: take a size, multiply by , add .
On the graph, a prediction is just: go up from the size, hit the line, read across to the price.
Which Line Is “Best”?
Here’s the problem. There are infinitely many lines you could draw. Which one is right?
Intuitively, the best line passes closest to all the dots. So we measure the miss. Watch how:
Three steps turn “how wrong is this line?” into a single number:
- For each dot, take the gap between the real price and the line’s prediction. That gap is the error (or residual).
- Square each gap.
- Average all the squared gaps.
That final number is the Mean Squared Error (MSE).
Why square the gaps? Two good reasons:
- It makes every error positive, so misses above and below the line can’t cancel out.
- It punishes big misses much harder than small ones, so the line really tries to avoid being wildly off.
Low MSE means the line hugs the data. High MSE means it’s way off. MSE is the loss for linear regression.
The Payoff
Now look at what we’re holding:
- a model with parameters , and
- a loss (MSE) that scores how wrong any choice of and is.
We already know exactly what to do with that. It’s a loss we want to shrink, so we reach for the tool from the last note: gradient descent. Start with a random junk line, feel which way to nudge and to lower the MSE, and step downhill. The line swings and slides into place until it hugs the data.
This is the first real model. Its parameters are and , its loss is MSE, and it is trained by gradient descent. The three ingredients from note 1, now made concrete.
And a lovely bonus: the MSE landscape for linear regression is a perfect single bowl, one global minimum with no shallow traps. So here, gradient descent is guaranteed to find the one best line. No getting stuck.
One Quick Extension
Real houses have more than size: bedrooms, age, location. No problem. Just add more weights:
It is still just a weighted sum plus a bias. And that shape, a weighted sum of inputs, is the single most important pattern in all of machine learning.
Hold on to it. A neuron, which we meet soon, is exactly this line, with one small twist on top.