01Why it matters
The first model everyone trains
Given some points, find the straight line that fits them best. It sounds like school geometry, but it is a complete machine-learning pipeline in miniature: a model (), a loss that says how wrong it is, and gradient descent nudging the parameters until the loss stops falling.
Every bigger model, up to large language models, is trained with the same three pieces.
02Key parts
The pieces you will see
- model
- The line : a weight (the slope) and a bias (where it crosses zero).
- residual
- How far a point is from the line vertically: .
- mean squared error
- The average of the squared residuals. Here each one is drawn as an actual square, so the loss is their average area.
- least squares
- The line with the smallest possible MSE, which also has an exact formula.
03See it work
Shrink the squares
The gradient of the MSE comes straight from the chain rule: each point pulls the line towards itself in proportion to its residual,
04Predict
Your turn: which way will it move?
Make 5 predictions: step forward and answer each question before the next step plays.
0 of 5 made05Try it
Drag the data
Drag any point and the fit runs again from the start. Try:
- Drag one point far from the others. Watch its square dominate the loss and drag the line towards it.
- Line the points up exactly. The final MSE goes to 0.
- Pick "Too big a step": with too large a learning rate, the line swings further each time and the loss explodes.
06Check yourself
Check yourself
Question 1 of 3
Three residuals are 1, −2 and 3. What is the mean squared error?
Your answer comes back in Review in a few days, so it sticks.
Question 2 of 3
Every point lies above the line. Which way does gradient descent move b?
Question 3 of 3
Why can one outlier move the least-squares line so much?
07Explain it back
Say it in your own words
What makes one line fit the data better than another, and how does gradient descent find the best one?
08Recap
What to remember
- A model, a loss and an optimiser: , the mean squared error, and gradient descent.
- Each point pulls the line in proportion to its residual; squared errors make outliers pull hard.
- Gradient descent reaches the same line as the exact least-squares formula when the step size is right.
- Next: replace the line with a curve made of many neurons, and the same recipe trains a neural network.