Loss Functions
One number that says how wrong a model is — the thing training tries to make small.
Step 1
Predict
Two lines: A misses every point by 0.2; B fits most points perfectly but misses one point by 0.8. Using mean squared error, which line has the smaller loss?
Step 2
Experiment
A loss function turns all the residuals into a single number. The most common one is the mean squared error (MSE): square each residual and average.
The shaded squares in the lab show each squared error. Move the line and watch the squares — and the MSE readout — shrink and grow.
🔒 Make a prediction first to unlock the experiment.
Loading experiment…
Tip: Big squares dominate the average. Fix the biggest ones first.
Step 3
Principle
For points and model , the mean squared error is
Training a model means finding the parameters that make the loss as small as possible. The loss turns “a good fit” into a precise target a computer can optimize.
Other choices exist: the mean absolute error is less sensitive to outliers; classification uses cross-entropy. The choice of loss decides what “good” means.
Step 4
Challenge
Move the line until the mean squared error is within 0.005 of the best possible value.
Residuals are 1, −1, 2 and 0. What is the mean squared error?
Why do we square residuals instead of just adding them up?