Part IV — Supervised Learning: Regression & Linear Classifiers · Chapter 2

Loss functions: MSE vs. MAE vs. Huber

Hook

One of your data points is way off from the rest. Should it get to boss around your line as much as everyone else?

Intuition

Notice the one point sitting far above the others. Drag the line near it, then away from it, and watch its dashed residual stretch and shrink far more dramatically than any of the rest.

Formalize

Two ways to average those residuals into one number — Mean Squared Error (MSE) and Mean Absolute Error (MAE):

MSE=1ni(yiy^i)2,MAE=1niyiy^i\text{MSE} = \frac{1}{n}\sum_i (y_i-\hat y_i)^2, \qquad \text{MAE} = \frac{1}{n}\sum_i |y_i - \hat y_i|
  • MSE — Mean Squared Error: the average of the squared residuals.
  • MAE — Mean Absolute Error: the average of the absolute residuals.
  • nn — the number of data points.
  • yiy_i — the actual (observed) value for data point ii.
  • y^i\hat y_i — the model's predicted value for data point ii.
  1. MSE lets one big miss dominate

    Squaring means a residual twice as large costs four times as much, so a single large miss can dominate the entire sum.

  2. MAE grows only proportionally

    Absolute value scales linearly with the size of the miss, so a single outlier can't hijack the total the way it can under squared error.

Play
MSE = 91.17 MAE = 7.92

Fit the five close-together points well, then watch both numbers. MAE settles down close to what it was without the outlier at all — MSE stays stubbornly large no matter where you put the line.

Worked example

With w=2,b=1w=2, b=1, the outlier at (2,20)(2, 20) has residual 205=1520 - 5 = 15.

  1. Its leverage under squared error

    Squared, that's 225225 — versus the other five residuals' squares summing to just 0.830.83, so the outlier accounts for over 99% of the total sum of squared errors (SSE).

  2. Its leverage under absolute error

    In absolute terms it's 1515 against the other five's 1.91.9 combined — still large, but only about 89% of the total.

  3. Compare the two

    The same point, two very different amounts of leverage.

Checkpoint

Fit the line so MAE drops below 4.0 — notice MSE won’t cooperate nearly as easily, no matter where you put the line.

MSE = 91.17 MAE = 7.92
Drag either end of the line to try it
Summary
MSE=1ni(yiy^i)2,MAE=1niyiy^i\text{MSE} = \frac{1}{n}\sum_i (y_i-\hat y_i)^2, \qquad \text{MAE} = \frac{1}{n}\sum_i |y_i - \hat y_i|

MSE punishes large misses so heavily that a single outlier can dominate the fit; MAE treats every miss proportionally, making it far more robust to one bad point. The choice of loss function is a choice about which mistakes you consider expensive.