The Learning Problem
Data, hypotheses, losses and risk: the setup behind every model.
Every method in this course answers one question: given examples drawn from a distribution you will never see, choose a rule that does well on the next draw. This lesson writes that question down exactly. You will derive the best possible predictor for each loss, watch empirical risk minimization memorize when its model class is too rich, and split the error of any learned model into the two parts every method trades off.
What you’ll learn
- Define the statistical learning setup: input and output spaces, an unknown distribution, an i.i.d. sample, a hypothesis class and a loss.
- Distinguish risk from empirical risk, define empirical risk minimization, and show that the training error of its output is optimistic.
- Derive the Bayes predictors: the conditional mean for squared loss and the most probable class for the 0–1 loss.
- Decompose excess risk into approximation and estimation error, bound the estimation error of ERM over a finite class, and explain why some inductive bias is unavoidable.
- Explain why convex surrogate losses replace the 0–1 loss in practice.
The setup, precisely
Inputs live in an input space (often ); outputs live in an output space : for regression, a finite set such as , or for classification. Examples are pairs drawn from a joint data distribution on that nobody knows. The training set consists of draws that are independent and identically distributed (i.i.d.) from .
A learning algorithm is a map from datasets to predictors, . Usually it chooses from a hypothesis class of functions , or when the prediction is a score or a probability.
| Loss | Formula | Used for | Remarks |
|---|---|---|---|
| 0–1 loss | classification | what you usually care about; neither continuous nor convex | |
| Squared loss | regression | smooth; large errors dominate | |
| Absolute loss | regression | less sensitive to outliers | |
| Log loss | probabilistic classification | is the predicted probability of the observed label; also called cross-entropy | |
| Hinge loss | classification with | is a real score, the prediction is ; used by SVMs |
The risk of is its expected loss on a fresh example; the empirical risk is its average loss on the training set:
You want small and can only compute . For a hypothesis fixed before the data are drawn, each term of has mean , so , and the law of large numbers gives . Empirical risk minimization (ERM) returns .
For a fixed , is an unbiased estimate of . What about , the training error of the ERM output?
- Also unbiased, by linearity of expectation
- Biased upward: training error overstates the risk
- Biased downward: was chosen to make it small
- Unbiased once exceeds the number of parameters
Show the answer
C. Biased downward: was chosen to make it small
Let minimize over . ERM guarantees on every sample, and is fixed, so . The same data chose and graded it.
The best possible predictor
Suppose you knew . Which function would you use? The answer, the Bayes predictor, depends on the loss. For squared loss (assuming ) it is the regression function .
Take any and add and subtract inside the square:
The cross term vanishes. Condition on : then is a constant, and has conditional mean zero by the definition of .
Two nonnegative terms remain, and only the first depends on :
So minimizes the risk (uniquely, up to changes on a set of probability zero), every other predictor pays its mean squared distance from , and the minimum is the average conditional variance: the noise floor.
For classification with the 0–1 loss, write . Predicting class at is wrong with conditional probability , so the best choice at each , separately, is the most probable class. Averaging over gives the Bayes classifier and its risk, the Bayes error:
Ties can be broken any way. The Convergence lesson Risk, Bayes Optimality & Excess Risk turns this pointwise argument into an exact formula for how much any other classifier loses.
| Loss | Bayes predictor at | Bayes risk |
|---|---|---|
| Squared | conditional mean | |
| Absolute | a conditional median of given | average absolute deviation from that median |
| 0–1 | most probable class | |
| Log loss | the true conditional distribution | the conditional entropy of given (see Information Theory for ML) |
A blood test returns low for 60% of patients and high for 40%. Among low results, 10% of patients have the disease; among high results, 70% do. What is the Bayes error of predicting the disease from the test result alone, in percent?
Show the answer
18 %
The Bayes classifier predicts "healthy" for low results (wrong 10% of the time) and "disease" for high results (wrong 30% of the time). So . No classifier that sees only this test result can do better than 18% error, however much data it has.
ERM, and how it memorizes
ERM needs a class, and the class matters. Let contain every function, and consider the lookup-table learner: predict at each training input and predict everywhere else. Its empirical risk is zero, so it is an ERM solution.
Now let the inputs be continuous measurements. A new coincides with a training input with probability zero, so the lookup table predicts almost everywhere, and its 0–1 risk is , which can be or worse, for every . Zero training error, no learning at all.
With nested classes , such as polynomials of degree at most , the minimal training error can only fall as grows: every fit available in is still available in . The risk of the ERM solution behaves differently.
You fit polynomials of degree and by least squares to the same training set. Which statement is always true?
- The degree- fit has test error at most that of the degree- fit
- Both training and test error decrease
- The degree- fit has training error at most that of the degree- fit
- Neither error can be predicted without seeing the data
Show the answer
C. The degree- fit has training error at most that of the degree- fit
Every degree- polynomial is a degree- polynomial whose top coefficient is zero, so the larger class can match any fit of the smaller one: the minimal training error cannot go up. Test error has no such guarantee, which is the whole point of the U-curve.
Two errors and an inductive bias
Let minimize over (assume a minimizer exists; otherwise take one within any ). Split the estimation error of the ERM output into three pieces:
The middle bracket is at most because minimizes . Each outer bracket is at most the largest deviation between empirical and true risk over the class:
For a finite class and a loss with values in , Hoeffding's inequality and a union bound over the hypotheses (proved in the Convergence lesson Probability & Concentration Inequalities) give, with probability at least over the sample:
ERM chooses among classifiers using examples. With probability at least 95%, its estimation error under the 0–1 loss is at most how many percentage points, by the bound above?
Show the answer
5.9 points
, so the bound is : about 5.9 points. The class size enters only through its logarithm: a million hypotheses cost about 14 nats, so even a thousandfold larger class would raise the bound only to about 7.0 points. Infinite classes need a different measure of size, the VC dimension of the topic Generalization & Model Selection.
Choosing , and any preference among its members, before seeing the data is the learner's inductive bias. A smaller or better-aimed class lowers estimation error at the risk of raising approximation error. No learner can do without one: the Convergence lesson No Free Lunch & Inductive Bias proves that for every learner there is a distribution on which it fails badly while another learner succeeds.
| Learner | Its inductive bias |
|---|---|
| -nearest neighbors | nearby inputs have similar labels (locality) |
| Linear and logistic regression | the response, or its log-odds, is linear in the features |
| Ridge and lasso | small coefficients; with the lasso, few nonzero ones (sparsity) |
| Decision trees grown greedily | axis-aligned, piecewise-constant rules, simple ones first |
| Convolutional networks | a pattern means the same thing wherever it appears in an image (translation equivariance) |
| Gaussian processes | with the usual kernels, smooth functions at a chosen length scale |
Think first Inputs are 10 binary features, so there are possible inputs. You see the correct label for 1,000 of them. How many functions agree with all 1,000 labels, and what do they say about the other 24 inputs?
functions fit the data perfectly, one for each way of labeling the 24 unseen inputs. On every unseen input, exactly half of them say and half say . The data rule out almost all functions yet decide no unseen label; only a bias (a smaller class, or a preference such as "similar inputs get similar labels") does.
Losses you can optimize
For classification the 0–1 loss is usually the loss you care about, but ERM with it is hard to carry out. The empirical 0–1 risk of a linear classifier is piecewise constant in , so its gradient is zero wherever it exists, and finding the best halfspace on data that no halfspace separates is NP-hard (the Convergence lesson The Computational Hardness of Learning has the details).
Practice therefore minimizes a convex surrogate of the margin , with labels and a real-valued score . A positive margin means a correct prediction; a large one means a confident correct prediction.
| Loss | Minimized by | |
|---|---|---|
| 0–1 | the target, not minimized directly | |
| Hinge | support vector machines | |
| Logistic | logistic regression | |
| Exponential | AdaBoost | |
| Squared | least-squares classification |
Key takeaways
- The learning problem: an unknown distribution on , an i.i.d. sample , a hypothesis class and a loss . Risk is the target, empirical risk its observable proxy, and ERM minimizes the proxy.
- The Bayes predictor depends on the loss: the conditional mean for squared loss, a conditional median for absolute loss, the most probable class for the 0–1 loss. Its risk is a floor no learner can beat.
- The training error of the ERM output is optimistic on average, and over a class that is too rich ERM memorizes: zero training error, no generalization.
- Excess risk = estimation error + approximation error. For a finite class and a loss in , ERM's estimation error is at most with probability at least . Choosing is an inductive bias, and no learner can avoid having one.
- In practice the 0–1 loss is replaced by convex, classification-calibrated surrogates (hinge, logistic, exponential), which are tractable to minimize and still aim at the Bayes classifier.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Under squared loss, which predictor has the smallest risk?
- The conditional median of given
- The least-squares line
- The most probable value of given
- The conditional mean
Show the answer
D. The conditional mean
, so the conditional mean minimizes the risk and attains the noise floor .
For binary classification, when is the Bayes error zero?
- When the two classes are equally frequent
- When the label is a deterministic function of the input: for almost every
- When the training set is large enough
- Never: there is always some noise
Show the answer
B. When the label is a deterministic function of the input: for almost every
, which is zero exactly when is or almost everywhere, that is, when determines .
You replace a hypothesis class by a strictly larger class and keep using ERM. Which of these is guaranteed?
- The approximation error does not increase
- The estimation error does not increase
- The excess risk decreases
- The training error increases
Show the answer
A. The approximation error does not increase
The approximation error is , and an infimum over a larger set can only be smaller or equal. The estimation error usually grows, so the excess risk can go either way.
A learner stores its training set, predicts the stored label for any input it has seen before, and predicts "no" otherwise. The inputs are continuous measurements. As , what happens to its risk?
- It tends to the Bayes error, because the table eventually covers everything
- It tends to zero
- It stays at , because new inputs almost never repeat a stored one
- It tends to for every distribution
Show the answer
C. It stays at , because new inputs almost never repeat a stored one
A continuous input repeats a stored one with probability zero, so the learner answers "no" almost always. Its training error is zero and its risk never improves: ERM over the class of all functions memorizes without learning.
Why do logistic regression and SVMs minimize the logistic and hinge losses instead of the 0–1 loss?
- The 0–1 loss is not what practitioners care about
- Surrogate losses always give lower test error than the 0–1 loss
- The 0–1 loss cannot be evaluated on real-valued scores
- Empirical 0–1 risk is piecewise constant and NP-hard to minimize over halfspaces in general, while convex, calibrated surrogates can be minimized efficiently and still aim at the Bayes classifier
Show the answer
D. Empirical 0–1 risk is piecewise constant and NP-hard to minimize over halfspaces in general, while convex, calibrated surrogates can be minimized efficiently and still aim at the Bayes classifier
Convexity makes the optimization tractable, and classification calibration ensures that minimizing the surrogate risk over all functions yields the Bayes classifier. The 0–1 loss remains the yardstick for evaluation.
Go deeper
- Risk, Bayes Optimality & Excess Risk · The best possible predictor, and how far learned ones fall short.
- No Free Lunch & Inductive Bias · Why every learner must assume something about the world.
- The Computational Hardness of Learning · When finding a good hypothesis is harder than fitting the data.
Further reading
- S. Shalev-Shwartz & S. Ben-David, Understanding Machine Learning: From Theory to Algorithms (Cambridge University Press, 2014), chapters 2–5.
- T. Hastie, R. Tibshirani & J. Friedman, The Elements of Statistical Learning, 2nd ed. (Springer, 2009), §2.4 (statistical decision theory).
- M. Mohri, A. Rostamizadeh & A. Talwalkar, Foundations of Machine Learning, 2nd ed. (MIT Press, 2018), chapters 2 and 4.
- F. Bach, Learning Theory from First Principles (MIT Press, 2024).