01
Errors into a number
A prediction can miss in many ways. A loss function decides how those misses count.
Three points. One imperfect line.
A model predicts 2 when the target is −1. On another example, it predicts 2.5 instead of 1. On a third, it gets 3 exactly right. Before we can improve the model, we need a consistent answer to a deceptively simple question: how bad is this set of predictions?
Our running example uses three invented, noiseless data points: A is , B is , and C is . In each pair, the first number is the input and the second is the target . We predict with a line:
The hat marks a prediction. The parameter controls the line's slope; , its intercept. Start with and . These choices produce the three predictions above. They are hand-picked teaching values, not the result of training.
Invented data, exact calculation (CL-005). Filled dots are targets; hollow dots are predictions. The line is ŷ = 0.5x + 2.5. Error means prediction minus target, so these gaps are nonnegative.
Measure the miss, then assign a penalty
Define the residual as prediction minus target:
The subscript identifies an example. A positive residual means overprediction under this sign convention; a negative one means underprediction. The residuals here are 3, 1.5, and 0. Simply adding signed residuals could let opposite mistakes cancel.
A per-example loss assigns a penalty to a prediction and its target. Squared loss uses , making either sign of error count positively. Our three penalties are therefore 9, 2.25, and 0.
Combine them with a mean to obtain mean squared error, or MSE. With scalar-output examples:
This is the squared-loss mean convention used throughout this guide: no extra factor of one half and no regularization term. The summation symbol says to add the penalties before dividing by the number of examples.
The reduction is part of the definition
A reduction is the rule that combines individual penalties. The sum here is 11.25; the mean is 3.75. Neither number is wrong, but they are not interchangeable. Duplicate every unchanged example and the sum doubles, while the mean stays 3.75.
We will use for an individual penalty and for the combined objective. In practice, “loss” often names either, so check the definition before comparing reported values. You now know where one loss number comes from. Next: why square the errors at all?