Suppose a delivery-time model predicts 8 minutes when the target is 5. Squared error gives (8 − 5)² = 9; absolute error gives |8 − 5| = 3. Squaring makes larger errors contribute disproportionately. These are illustrative calculations, not scores from a deployed system.
A classifier can use cross-entropy to penalize probabilities assigned to the wrong category. A language model can use a similar objective for target tokens. Losses may be averaged over examples or combined with a regularization penalty. A loss API can return per-example values before that aggregation; it need not always return one scalar immediately.
Two error patterns under two losses
Take two deliveries, each with a target of five minutes. Pattern A predicts seven minutes for both; pattern B predicts five and nine:
| Measure | Pattern A | Pattern B |
|---|---|---|
| Errors in minutes | 2, 2 | 0, 4 |
| Mean absolute error | 2 minutes | 2 minutes |
| Mean squared error | 4 minutes² | 8 minutes² |
Absolute error treats the two patterns as equally good. Squared error scores B twice as badly, because squaring turns its one four-minute miss into 16, against 4 + 4 for A’s two small misses. Which pattern the model is pushed toward depends on the loss you choose, and MSE’s squared units mean an MSE of 4 and an MAE of 2 cannot be compared as if they were the same score. Record the reduction too: whether per-example losses were averaged or summed, and over what, changes the reported number without changing a single prediction.
The choice matters because the optimizer follows the objective it receives, usually through some form of gradient descent. A falling training loss does not establish good task success if the targets miss important requirements or the data differs from deployment. Evaluate the behavior users need on held-out examples, alongside the training objective.
Sources
- Keras: Losses — Defines losses as training objectives and documents targets, prediction inputs and reduction choices.
Go deeper
- Google: Linear regression loss course
Compare absolute and squared error with worked regression examples.