Lab: train a model yourself
Put the whole section together. Build a dataset, train linear regression with gradient descent, debug the learning rate, then take the section quiz.

In this lesson you will
- Train a linear regression model end to end with gradient descent
- Diagnose training from the path on the contour map and the loss curve
- Explain how the data, the starting point and α affect the result
- Check your understanding of the whole section with the section quiz
This is where it all comes together. Below is a complete, if tiny, machine learning system: a dataset, a model , a cost and an optimiser, gradient descent. Everything a large model does, this does too, just with two parameters instead of billions.
How the lab works
- Left, the data and the model. Pick a preset dataset, or tap empty space to add a house and tap a point to remove it (the buttons do the same from the keyboard). The blue line is the current model.
- Middle, the contour map of . The trail shows every step gradient descent has taken. Click the map to choose a different starting point.
- Right, the loss curve. The cost after every iteration.
- Controls. Set the start values and , then Step one iteration at a time or Run. Reset goes back to the start. Show the answer draws the exact best line (computed directly with a formula) so you can check what gradient descent found.
This lab is a complete learning system: data, a line, a cost, and gradient descent.
Challenges
The lab ticks these off as you complete them:
- Train to on the House prices preset. Start from , with and press Run. Compare your line with Show the answer.
- Find a learning rate that diverges. Raise a little at a time. What does the path on the contour map look like just before it blows up, and just after?
- Converge in under 100 iterations. You’ll need a well-chosen , and maybe a better starting point.
- See the effect of an outlier. Load the One outlier preset and train. One badly priced house drags the whole line toward it, because squaring makes its large error count a lot. Remove it and train again.
- Fit your own data. Add at least three houses of your own and train a model on them.
Questions to think about
- Starting points: does gradient descent always reach the same line, wherever you start? (For this bowl-shaped cost, it should. Why?)
- Why does the loss curve drop steeply at first and then flatten?
- On the Flat — no trend preset, what value does end up near, and what does that mean about how price depends on size in that data?
Section 1 quiz
You’ve finished the first section. This quiz covers everything from what machine learning is to choosing a learning rate; each answer comes with an explanation.
Self-check · 10 questions