Machine learning with football · Chapter 2 · Linear regression

Loss

One number for how wrong a line is, five ways to compute it, and what a single freak team does to each.

Estimated time: 15 minutes · page 2 of 7

A number for how wrong the line is

Each dotted stick on the board is one team's error, the gap between its real points per game and what the line predicted. Loss turns all those gaps into one number, and training tries to get it as low as it can.

A gap can be above or below the line. Add them up as they are and a miss of +0.3 cancels a miss of −0.3, so every loss first gets rid of the sign, either by taking the size of the gap or by squaring it. That gives five common losses:

LossHowUnits
L1 lossadd up the size of every misspoints per game
Mean absolute error (MAE)L1 loss ÷ number of teamspoints per game
L2 lossadd up every miss squaredsquared
Mean squared error (MSE)L2 loss ÷ number of teamssquared
Root mean squared error (RMSE)√MSEpoints per game

Say the line predicts 2.1 points per game for the leaders and they really have 2.3. The miss is 0.2, so its L1 loss is 0.2 and its L2 loss is 0.2² = 0.04. Squaring shrinks misses under 1 and blows up big ones, which matters a lot once one team is far off.

MSE = average of (y′ − y)²

goal differenceMiss → squared+0.2 → 0.04−0.3 → 0.09+0.8 → 0.64MSE = 0.77 ÷ 3 ≈ 0.26
Each miss becomes a square. The right-hand miss is four times as long as the left-hand one and costs sixteen times as much.

MAE and RMSE are back in points per game, so they read like a typical miss. The board shows all three for your line. A loss of 0 would mean every dot sits exactly on the line, which never happens in football. Luck, draws and late goals push teams above or below what their goal difference says.

Check yourself

Why does MSE square each error before averaging?
Ten teams. Line A misses four of them by 0.1 points per game and the rest not at all. Line B misses two by 0.2 and the rest not at all. Which line has the higher MSE?
And which of the two has the higher MAE?

One team far off the line

An outlier is an example far from the rest. Tick Add an outlier on the board. It adds a made-up team that loses half a goal a game but still collects title-race points. Then show the best lines. The dashed one has the lowest MSE and tilts toward the outlier. The orange dotted one has the lowest MAE and barely moves.

That's the squaring at work. The outlier's miss is big, and squared it counts for more than several normal teams together, so the MSE line gives up a little on everyone else to get closer to it.

Which loss to pick

  • MSE when big misses are much worse than small ones, or when the outliers are real and matter. It is also smoother, which gradient descent likes.
  • MAE when a few odd examples should not drag the whole model around, or when you want the plain average miss.

What a miss costs in the real world decides it in the end. For a bookmaker, one very wrong price can cost more than many slightly wrong ones.

Check yourself

You want a model of points per game that a few freak seasons do not drag around. Which loss do you train with?
A betting model where being off by 1 goal is fine but being off by 3 loses a lot of money. Which loss fits better?

Terms on this page: L1 loss, L2 loss, Loss, Mean absolute error (MAE), Mean squared error (MSE), Outlier, Root mean squared error (RMSE)

Leagues