Linear regression, by hand
Linear regression fits a straight line through data to predict one number from another — the simplest useful machine-learning model, and the foundation for much of what follows. The 'best' line is the one that makes the total squared error between the line and the points as small as possible.
By dragging the line yourself and watching the error rise and fall, you build the exact intuition that gradient descent automates when it trains bigger models.
Drag the line to fit the dots
Mean squared error
0.444
best possible is 0.116 — the amber misses are what MSE squares and averages
Free · runs entirely in your browser · nothing to install
How to use it
- Drag the line's slope and position to fit the scattered points.
- Watch the error value shrink as your line gets better.
- Hit 'best fit' to see the mathematically optimal line and compare.
What you'll take away
- What 'fitting a model' actually means.
- Why we minimise squared error.
- How manual fitting connects to automatic training.
Want to actually build this?
This demo is one moment inside a full Math to Machine lesson — predict, build, and explain the concept, with an AI tutor that gives hints, not answers. The first five lessons are free.
FAQ
- What is linear regression?
- It's a method for modelling the relationship between an input and an output as a straight line, chosen to minimise the squared differences between the line's predictions and the real data points.
- Why is linear regression a good first model to learn?
- It contains every core idea of machine learning — parameters, a loss function, and optimisation — in the simplest possible form, so the intuition transfers directly to neural networks.