Empirical Risk Minimization
The rule behind almost every fitted model — since you cannot measure error on data you have not seen, minimise average error on the data you have. It works, right up until the model starts memorising the sample instead of learning the world.
Prerequisites: The Supervised Learning Framework, Expected Value
You want the model that will be least wrong on cases you have not met yet. That quantity is unmeasurable by construction — the cases have not happened. So every practical fitting procedure makes the same substitution: score candidate models on the data you do have, and pick the winner. That substitution is empirical risk minimization, or ERM, and it is the engine inside ordinary least squares, logistic regression, support vector machines, boosted trees and neural networks alike.
The everyday version is choosing a restaurant from its reviews. What you care about is how good your dinner will be. What you can measure is the average of a few hundred dinners other people already had. The average is not the thing you want, but it is evidence about the thing you want, and with enough reviews it is good evidence. With three reviews it is not.
The two risks
The thing you want is the true risk — the expected loss over the whole data-generating process:
Read it as: how badly rule does on average, over every case the world could ever produce. The thing you can compute is the empirical risk — the same average, taken over your rows instead of over the world:
Read it as: the average loss the rule racked up on the examples you actually have. ERM is then a single line: search your hypothesis class and return whichever rule scores lowest.
That is the whole idea. Everything else in this page is about the gap between the two risks.
ERM optimises a proxy. is an unbiased estimate of for a model chosen before you looked at the data — but was chosen because it scored well, so is biased downward. The bigger the class you searched, the bigger the lie.
Worked example 1: two candidate lines
Five observations of a signal and a return :
| 1 | 2 | 3 | 4 | 5 | |
|---|---|---|---|---|---|
| 2.2 | 2.8 | 4.5 | 4.7 | 6.3 |
Use squared loss, . Candidate A is ; candidate B is .
A predicts . The errors are ; squaring and adding gives , so .
B predicts , with errors . The squares sum to , so .
ERM picks A. And if you let the search run over all lines rather than just these two, you get the least-squares fit with — which is exactly what Ordinary Least Squares (OLS) is: ERM with squared loss over the class of linear functions.
Drag the points below and watch the fitted line chase them. The vertical stubs are the residuals; ERM is the machine that makes the sum of their squares as small as it can.
Worked example 2: picking a threshold
Now a classification problem with 0-1 loss (one unit per mistake). Eight days, each with a signal value and a realised direction:
| signal | 0.1 | 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 |
|---|---|---|---|---|---|---|---|---|
| label | down | down | down | up | up | down | up | up |
The class is "go long when the signal exceeds ", one rule per threshold. Take : it calls up on the last five days, which are up, up, down, up, up — one mistake — and down on the first three, all correct. So . Take : it calls up on the last three (down, up, up — one mistake) and down on the first five (three of which were up — two more mistakes), giving . Take : three mistakes above the line, none below, again .
ERM returns . But notice how little separates the candidates: one flipped day would change the answer. That fragility is the real lesson.
What this means in practice
Almost every named algorithm is ERM with a different loss and a different class. Ordinary Least Squares (OLS) is squared loss over linear functions. Logistic Regression is log loss over linear functions. Support Vector Machines is hinge loss plus a size penalty. Gradient boosting is ERM over sums of trees, solved greedily. Recognising this collapses a dozen "methods" into one idea with knobs.
The fix for the gap is not to optimise harder — it is to shrink what you optimise over. Regularised ERM adds a complexity penalty:
which says: pay for fit, but also pay for complication, with setting the exchange rate. That is Ridge and LASSO Regularization, and it is why a slightly worse training score often buys a much better live one.
Pure ERM over an unrestricted class is useless. A lookup table that memorises every training row has empirical risk exactly zero and predicts nothing. Low training loss is not evidence of learning — the only evidence is loss on data the search never touched.
Related concepts
Practice in interviews
Further reading
- Vapnik, The Nature of Statistical Learning Theory (Ch. 1–3)
- Shalev-Shwartz & Ben-David, Understanding Machine Learning (Ch. 2, 4)
- Hastie, Tibshirani & Friedman, The Elements of Statistical Learning (Ch. 7)