Linear regression: your first model
Fit a straight line to house prices, learn the notation every ML paper uses, and make your first prediction ŷ.

In this lesson you will
- Use the standard notation for a training set (x, y, m and the i-th example)
- Write the linear model f(x) = wx + b and explain what w and b do
- Use a model to make a prediction ŷ for a new input
Time to build your first machine learning model. The task: a friend is selling a house of 1,500 square feet and asks what it might sell for. You have a list of recent sales in the neighbourhood. Can the data give a sensible answer?
The training set and its notation
The data a model learns from is its training set. Every machine learning text uses the same short names, so it’s worth learning them once:
- is the input (also called a feature): here, the size of a house in thousands of square feet.
- is the output or target: the price it sold for, in hundreds of thousands of dollars.
- is the number of training examples.
- is the -th training example. The is a label, not a power: just means “the size of the second house”.
So if the third house is 1,500 sq ft and sold for $310k, then and .
The model: a straight line
The learning algorithm’s job is to produce a function , the model, that takes a new and outputs a prediction. We write the prediction as (“y hat”): our estimate of the true .
The simplest model that can capture “bigger houses cost more” is a straight line:
It has two numbers we get to choose, called the model’s parameters:
- , the weight or slope: how much the predicted price rises for each extra 1,000 sq ft.
- , the bias or intercept: where the line crosses the vertical axis, the price it predicts for a size of zero (a baseline, not a real house).
Because there is a single input feature, this is called linear regression with one variable (or univariate linear regression).
Drag the line yourself
The dots are 24 real-looking sales. Move and with the sliders, or grab the line itself: drag its middle to shift it up and down, drag the round handle to tilt it. Then use the House size probe to read off the model’s prediction for your friend’s house.
Each dot is a house that sold recently. Size runs along the bottom, and price runs up the side.
Some things worth noticing:
- Different values of and give different models and different predictions for the same house. Training means picking good ones.
- Even the best line doesn’t pass through every dot. Real prices depend on more than size, so a good model is one whose misses are small overall.
- With and the line hugs the data, and for 1,500 sq ft it predicts , about $330k.
You found good values by eye. But “looks about right” is not something a computer can do. In the next lesson we turn “how good is this line?” into a single number the computer can make smaller.
Check yourself
Self-check · 4 questions