TL;DR
- Now is unknown; we see training points drawn i.i.d. from . The goal is a function with .
- An algorithm is consistent for if for every , and universally consistent if this holds for every (Stone 1977: kNN). Consistency is about the risk, not about .
- The empirical risk converges to for every fixed (law of large numbers, Proposition 6). ERM picks .
- ERM is not always successful: a function that memorizes the training points has but . The LLN does not apply because depends on all data points.
- The excess risk splits into estimation error (random, grows with the size of ) and approximation error (deterministic, shrinks with the size of ). Classical regime: U-shaped test risk. Modern regime: interpolation, double descent. For the loss, pointwise: .
- No Free Lunch: averaged over all possible true functions, all classifiers perform the same. Machine learning without an inductive bias is impossible.
Exam relevance
- Multiple choice (task 1 of the real exam, task 2 of the mock): what consistency means and what it does not mean, universal consistency (kNN), which error term is random, over- vs. under-parameterization, what NFL does and does not say. The mock asked exactly such statements; see the MC block below.
- Table tasks: empirical risks from a small sample, the ERM choice, estimation and approximation error from given true risks, bias and variance from a few predictions. Worked examples: ERM task, bias-variance task, NFL task.
- Sheet 2, Exercise 2 is the NFL on (kNN vs. memorize-or-zero, averaged over all target functions).
Overview: 1. The finite sample setting and consistency, 2. Estimating the risk by the empirical risk, 3. Empirical risk minimization and why it can fail, 4. Estimation and approximation error, 5. The bias-variance decomposition, 6. The No-Free-Lunch theorem.
Predicting in the finite sample setting
Finite sample setting and the training data
Slides 105-108
So far we discussed the “optimistic” regime in which we know the underlying distribution: then there is nothing to learn. Now we turn to the standard machine learning setting: we do not know the distribution, but we see samples from it (Bach Sec. 2, Devroye et al. Sec. 2, Hastie et al. Sec. 2.4-2.9). Everything we do has an attached uncertainty that depends on how well the sample represents .
Training data
We draw training points i.i.d. (independent and identically distributed) according to .
The i.i.d. assumption makes a lot of sense in many cases (to some degree even for blocks of text in language model pre-training), and it lets us use many tools from statistics. But it is a strong assumption in many applications: time series (today’s weather depends on yesterday’s), patients from the same hospital or family, repeated measurements of the same person. A second issue the framework does not cover: different train and test distributions (a model trained on data from one hospital, used in another).
The goal of machine learning
Slide 109
Goal
Given training points, construct a function whose true risk is close to the Bayes risk: .
depends on the random sample, so is a random variable. To make “close” precise we need convergence of random variables.
Recap: convergence of random variables
Slide 110
Three modes of convergence
Let be random variables and a random variable. converges to
- in probability if
- almost surely (a.s.) if
- in / in expectation if
Almost sure convergence implies convergence in probability, convergence implies convergence in probability, and there are no other implications in general.
Consistency of a learning algorithm
Slides 111-113
Consider an infinite sequence of data points drawn i.i.d. from , and let be the function the algorithm constructs from the first points.
Consistency
- is consistent (for ) if the risk of converges to the Bayes risk in probability:
- With almost sure convergence instead, is strongly consistent.
- is universally consistent if it is consistent for all distributions on .
Universal consistency
No matter what the distribution is, after “enough data points” the true risk of is arbitrarily close to the best possible risk. This is what we ultimately want.
What consistency does not say
- It is about the convergence of the risk , not about the function: need not converge to (pointwise or otherwise). Two very different functions can have the same risk.
- It is an asymptotic statement. It gives no rate: how many points are “enough” depends on , and for every fixed there are distributions for which is still far from .
For a long time it was unknown whether universally consistent algorithms exist at all. The first positive answer came in 1977, when Stone proved that the kNN classifier is universally consistent (with and ; with a fixed , for example , the noise of the nearest neighbour’s label never averages out). Since then, many algorithms have been shown to be universally consistent: support vector machines, boosting, random forests and more. Understanding the principles behind such results is a large part of this course.
Why not use the plug-in classifier and be done?
Slide 114
Idea: estimate the regression function by some from the training data and plug it into the Bayes classifier:
- In theory: with a suitable estimator , the plug-in approach is universally consistent. ☺
- In practice: estimating densities is notoriously hard, in particular in high-dimensional input spaces. We would need a ridiculous amount of training data, so the plug-in approach is useless in practice. ☹
Estimating the true risk by the empirical risk
Empirical risk
Slides 115-118
We defined the best classifier as the one that minimizes the true risk. Without we cannot compute the true risk. The obvious idea: estimate the risk from the sample and pick the function with the smallest estimated risk. The big question is whether this is (always? sometimes?) successful. First we look at how to estimate the risk of a fixed, given function .
Empirical risk
It can be computed from the training points alone. For the 0-1 loss it is the fraction of misclassified training points.
Is it a “good” estimate? A formal way to say this: converges to as .
Recap: law of large numbers
Slides 119-121
Proposition 5 (law of large numbers, simplest version)
Let be independent random variables drawn from a distribution with expectation . Then (under mild assumptions)
Mini example: why independence is crucial
Let be the toss of a fair coin and identical copies of . Each is with , but they are not independent. Depending on , the empirical average is always 0 or always 1, so it never converges to .
“Mild assumptions”: there are many versions of the LLN. Often it is stated for random variables with finite variance, which makes the proof much simpler, but it also holds as long as the expectation exists. The do not even need to be identically distributed, as long as they have the same expectation.
Convergence of the empirical risk of a fixed function
Slides 122-124
Proposition 6 (empirical risk converges for a fixed function)
In the standard setup, fix a function . Then for this fixed
Proof
Apply the law of large numbers to . These are independent (the points are i.i.d. and does not depend on them), with .
What it means, and what not
- For each fixed function, the training error is a good estimate of the test error when is large.
- It says nothing about how fast (no rate), and nothing about a function that was chosen using the data. That is exactly what a learning algorithm does, and it is the limitation that the next sections run into.
Empirical risk minimization
The ERM principle
Slides 125-127
For a fixed , the empirical risk converges to the true risk. So to find (which minimizes the true risk), it makes sense to pick the function that minimizes the empirical risk and hope that it is close.
Empirical risk minimization (ERM)
- Define a set of functions .
- Choose a function with the smallest empirical risk:
It might not be unique. For simplicity we assume the minimizer exists (otherwise one argues with a sequence approaching the infimum).
The function class is the important “parameter” of ERM: all linear functions, all decision trees of depth 5, all random forests, all two-layer MLPs, …
”Classical” regime vs. “modern” regime
Slide 128
Two regimes
- Classical regime: the function class does not allow for interpolation.
- Modern regime / interpolation regime: is so large that the training data can be interpolated (fitted with training error 0).
Is ERM always successful?
Slides 129-132
In our framework, a “successful” classifier is a consistent one. So: does ERM always converge?
Counterexample (slide 130)
- with the uniform distribution. Labels are deterministic: for and for .
- Draw training points. Define : on the training points, predict the training label; on all other points, predict .
- Then but for all (the set of training points has probability 0, so predicts almost everywhere and is wrong on the right half).
- With : always, but .
Why can’t we use the LLN? The key property in the LLN is independence. Here , but depends on all data points . So even though the points are independent, the are not: they all depend on .
Trap
Slide 129 writes the question as ”?“. This is the gap between training and test error of the selected function. The consistency question is . In the counterexample both fail: the gap stays , and .
Preview: statistical learning theory
It is not true that the minimizer of the empirical risk always converges to the Bayes classifier. Is machine learning doomed? No: statistical learning theory (Lecture 3) gives conditions on under which ERM works after all.
ERM in practice
Slide 133
- Conceptually, ERM is a straightforward learning principle. The key to its success or failure is choosing a “good” function class : explicitly (classical regime) or implicitly (interpolation regime, sometimes).
- Computationally it can be hard: finding the minimizer of the 0-1 loss is often NP hard. This is why in practice we use convex relaxations of the 0-1 loss: the surrogate losses of Lecture 1.1.
Estimation and approximation error
Definitions
Slides 134-135
When we perform ERM we can make two types of error. Let be the true best function in .
Estimation and approximation error
- Estimation error : a random variable that depends on the sample.
- Approximation error : a deterministic quantity that does not depend on the sample, only on the choice of .
Decomposition of the excess risk
Task: ERM, estimation and approximation error
Exam-style task: ERM on a small sample (4 P)
is uniform on with given below. with threshold classifiers iff . The training sample is
1 2 3 4 0.1 0.6 0.3 0.9 (a) (1 P, easy) Compute for all (0-1 loss). Which function does ERM select?
(b) (1.5 P, harder) Compute the true risks, , and the estimation and approximation error of ERM.
(c) (1.5 P, transfer) Now let be all functions . What happens to the approximation error, and what can happen to the estimation error?
Solution
(a) predicts 1 on : one error at , . : errors at both and at , . : errors at both and at , . ERM selects . (1 P)
(b) : , , . The Bayes classifier predicts 1 on (where ): (0.5 P). . Approximation error , estimation error . (1 P) Note that is far too optimistic.
(c) The Bayes classifier is now in , so the approximation error is 0 (0.5 P). ERM predicts 0 at , 1 at and ; at the sample has one 1 and one 0, a tie. If ERM picks 1 there, and the estimation error is ; if it picks 0, it finds the Bayes classifier. Both have : a larger class lowers the approximation error, but the training error can no longer tell good and bad functions apart. (1 P)
The classical regime
Slides 136-138
In the classical regime, is reasonably small (no interpolation). Then the two errors behave in opposite ways as grows:


Overfitting and underfitting (classical regime)
- Overfitting: is very large, so some explains all training points very well or exactly. Such a function tends to be complicated and models the noise as well, so predictions for unseen points are poor (large test error). Low approximation error, high estimation error.
- Underfitting: the model is too simple, is too small. The estimated functions are stable with respect to noise, but cannot represent the truth. Large approximation error, low estimation error.
The modern regime and double descent
Slides 139-141
In the modern regime the function class is huge and covers pretty much all possible functions.
- The empirical risk minimizer interpolates the training points ( has training error 0).
- The approximation error is often close to 0: the functions can represent almost anything.
- Traditional reasoning predicts a huge estimation error because of overfitting.
- But some algorithms always find solutions that interpolate and generalize well; these have a small estimation error. Practice shows that overfitting can even be beneficial.
There exist many functions with training error close to 0. Most of them would not generalize, some might. The question is how to find those.


Double descent
Below the interpolation threshold the classical picture holds. At the threshold the model is just able to fit the data and the test risk peaks. Beyond it, in the over-parameterized regime, the test risk falls again, often below the classical sweet spot. Why this can work is the topic of Lecture 8.
The bias-variance decomposition
Bias-variance tradeoff in L2 regression
Slides 142-147
Another decomposition of the error is most simple for regression with the squared loss. Let be constructed from random sample points and the regression function. For a fixed point , with the expectation over the random draw of the sample:
Bias-variance decomposition
- Variance term: the variance of the random variable .
- Bias term: how much and deviate.
For every loss we have "" in this spirit, but for the loss we get equality (as in Proposition 3).
Proof
Add and subtract inside the square (all expectations over the sample, fixed):
In the last term, is deterministic and can be pulled out of the expectation. What remains is by linearity.
Intuition
- Variance has the same intuition as the estimation error: it depends on the random data and on the capacity of .
- Bias has the same intuition as the approximation error: it does not depend on the data, only on the capacity of .
The classical picture (slide 147): as model complexity grows, the bias falls, the variance rises, and the test error is U-shaped.
Task: bias and variance from predictions
Exam-style task: bias and variance at one point (4 P)
An algorithm is trained on four independent training sets. At a fixed point it predicts (each with probability ). The true regression function is .
(a) (1 P, easy) Compute the bias term and the variance term.
(b) (1.5 P, harder) Verify the decomposition. Then use the shrunk predictor : bias, variance and expected squared error?
(c) (1.5 P, transfer) Which shrinkage factor minimizes the expected squared error of at ? What does this say about bias and variance?
Solution
(a) . Bias term . Variance . (1 P)
(b) Directly: ✓ (0.5 P). For : mean , bias term , variance , total : much better than . (1 P)
(c) . Setting the derivative to 0 gives and . Shrinking adds bias but removes more variance. This is the idea of regularization (Lecture 5). (1.5 P)
The No-Free-Lunch theorem
Intuition and setup
Slides 148-151
(Presentation after Ho and Pepyne 2002; see also Shalev-Shwartz and Ben-David Sec. 5.1 and Devroye et al. Chapter 7.)
Intuition
There is no single best classifier that outperforms all other classifiers when averaged over all possible learning problems. There are many formal versions; the lecture uses the easiest one.
NFL setup
- The input space is a finite set with a fixed distribution, say uniform (the proofs work for all distributions).
- Binary classification, , and the labels are deterministic functions of the input.
- There are functions ; call the set of all of them .
- One of them, , is the true function; we observe noise-free training points and an algorithm estimates .
- Table: rows are the estimated functions , columns the true functions , and the entry is the true 0-1 error of when the true function is .
With the uniform distribution, is the fraction of points where and disagree.
Trap
The bullet text on slide 151 says “rows = true functions, columns = estimated functions”, the drawing and the definition of use the other orientation. The statements below hold either way: they only count how many functions disagree with a given one on points.
Propositions 7 to 9
Slides 152-155
Proposition 7 (the risk in each row is the same)
In each row of the table, each risk value occurs the same number of times.
Proof
Fix a row . Then exactly once (when ), exactly times (the functions that disagree with on one point), exactly times, and in general exactly times. These counts do not depend on .
Proposition 8 (simple NFL)
On average over all true functions , the performance of all classifiers is the same.
Proof: obvious consequence of Proposition 7 (every row has the same multiset of values, so the same average).
Proposition 9 (simple NFL with training data)
Given a training set : on average over all true functions that could have generated the training data, all estimated classifiers with 0 training error perform the same.
Proof
In the table, eliminate all columns that are not consistent with the training data. Among the remaining true functions, all labelings of the test points are possible, each exactly once. Every classifier with 0 training error agrees with them on the training points, and on the test points the same counting argument as in Proposition 7 applies.
Task: No Free Lunch on three points
Exam-style task: NFL (4 P)
with the uniform distribution, labels . The only training point is . Classifier A predicts everywhere. Classifier B predicts at and at and . Write functions as label triples, for example .
(a) (1 P, easy) List all true functions consistent with the training data.
(b) (1.5 P, harder) Compute the average true error of A and of B over these functions.
(c) (1.5 P, transfer) Assume the inductive bias “similar inputs, similar labels”: along the label changes at most once. Recompute the averages and explain the difference.
Solution
(a) , , , : the labels at and are free. (1 P)
(b) A has errors , average . B has errors , average . Equal, as Proposition 9 says. (1.5 P)
(c) changes the label twice and is excluded. A: , average . B: , average . Deleting columns breaks the symmetry of the table, and the classifier that matches the assumption wins. Without an assumption no classifier can be better; with one, some are. (1.5 P)
Discussion
Slides 156-159
We have seen that “the best possible classifier for all data sets” does not exist. Should we give up? Is machine learning meaningless?
No: machine learning needs an inductive bias
- In practice we do not consider all possible functions. As soon as we make assumptions on the function space (or even just exclude pathological functions), the NFL breaks down: assumptions restrict the set of possible true functions, which deletes columns from the table, and the proof breaks down.
- Example: a notion of similarity among the inputs , and only functions that give similar labels to similar points. This excludes functions that look as if they distribute labels randomly.
- Machine learning without an inductive bias is impossible!
Much more general theorems exist, for example for data drawn from a joint distribution on with any space (Wolpert 1996, Ho and Pepyne 2002, Devroye et al. Chapter 7).
The lecturer's question: why doesn't the NFL contradict universally consistent algorithms?
Universal consistency is an asymptotic statement for each fixed distribution: for every , the risk converges to as . The NFL is a statement for a fixed training set size, averaged over all possible true functions. Both are true at the same time: for any fixed there are distributions on which a universally consistent algorithm is still bad (there is no uniform rate), but for each single distribution it eventually learns. In the finite NFL setting, once the training set covers all of , every consistent algorithm is perfect, and the NFL has nothing left to average over.
Summary
| Concept | Definition | Key point |
|---|---|---|
| Consistency | about the risk, asymptotic, no rate | |
| Universal consistency | consistent for every | exists: kNN (Stone 1977), SVM, boosting, random forests |
| Empirical risk | for a fixed (LLN) | |
| ERM | can fail: depends on the data | |
| Estimation error | random, grows with | |
| Approximation error | deterministic, shrinks with | |
| Variance / bias () | / | same intuition as estimation / approximation |
| No Free Lunch | averaged over all true functions, all classifiers equal | learning needs an inductive bias |
Self-Test
Question cards (13)
What is the i.i.d. assumption, and where does it fail?
Answer
The training points are drawn independently from the same distribution . It fails for time series, grouped data (patients of one hospital, repeated measurements) and when train and test distributions differ.
Define consistency, strong consistency and universal consistency.
Answer
Consistent for : . Strongly consistent: the same with almost sure convergence. Universally consistent: consistent for every distribution .
Name two things consistency does not guarantee.
Answer
That converges to as a function (only the risk converges), and any rate: how large must be depends on , and for every fixed there are distributions where is still bad.
Which algorithm was first shown to be universally consistent, and under which condition?
Answer
The kNN classifier (Stone 1977), with and . With a fixed (for example 1-NN) it is not universally consistent.
What is the plug-in classifier, and why is it useless in practice?
Answer
Estimate by and predict 1 iff . It is universally consistent with a suitable estimator, but estimating densities in high dimensions needs a ridiculous amount of data.
State Proposition 6 and its proof. Why does it not show that ERM works?
Answer
For a fixed , a.s., by the LLN applied to . ERM selects using the data, so the are no longer independent and the LLN does not apply.
Give the counterexample showing that ERM can fail.
Answer
uniform on , for and otherwise. returns the training label on training points and elsewhere: but for all .
Why does one minimize surrogate losses instead of the 0-1 loss in practice?
Answer
Minimizing the empirical 0-1 loss is often NP hard. Convex relaxations (hinge, logistic, …) can be minimized efficiently and are classification-calibrated.
Define estimation and approximation error and say which one is random.
Answer
With : estimation error (random, depends on the sample), approximation error (deterministic, depends only on ). They sum to the excess risk .
How do the two errors behave as grows in the classical regime, and how does that relate to over- and underfitting?
Answer
The approximation error falls, the estimation error rises, the true risk is U-shaped. Underfitting: small , large approximation error, low estimation error. Overfitting: large , low approximation error, high estimation error.
What is different in the modern (interpolation) regime?
Answer
is so large that ERM interpolates the training data and the approximation error is about 0. Classical reasoning predicts a huge estimation error, but some algorithms find interpolating solutions that generalize well; the test risk shows double descent beyond the interpolation threshold.
State and prove the bias-variance decomposition.
Answer
. Add and subtract , expand; the cross term is .
State Propositions 7, 8 and 9 of the NFL and the main conclusion.
Answer
7: in each row of the error table each risk value occurs equally often ( times). 8: averaged over all true functions, all classifiers perform the same. 9: averaged over all true functions consistent with the training data, all classifiers with 0 training error perform the same. Conclusion: learning needs an inductive bias that excludes some true functions.
Multiple Choice
Multiple choice (8)
A learning algorithm is consistent for . Which statement follows?
for almost every .
for every .
for a constant that does not depend on .
The algorithm is consistent for every other distribution as well.
Explanation
Consistency is convergence in probability of the risk. It says nothing about the function itself, gives no distribution-free rate, and holds for this only (for all it would be universal consistency).
Which of the following is universally consistent?
the 1-nearest-neighbour classifier
ERM over the class of linear classifiers
kNN with and
the plug-in classifier with any estimator
Explanation
Stone’s theorem. 1-NN never averages out the label noise; ERM over a fixed class converges at best to the best function in the class, which has an approximation error; the plug-in classifier needs a suitable estimator.
Why can the law of large numbers not be used to show for the ERM solution ?
because the loss is not bounded
because the training points are not identically distributed
because depends on all training points, so the losses are not independent
because the empirical risk is not an average
Explanation
The training points are i.i.d., but the summands all depend on the data-dependent . Independence is the key assumption of the LLN (compare the coin example of slide 120).
In the classical regime, the function class is made larger. What typically happens?
both the approximation and the estimation error decrease
the approximation error decreases, the estimation error increases
the approximation error increases, the estimation error decreases
the Bayes risk decreases
Explanation
A larger class contains functions closer to (lower approximation error) but also more functions that fit the noise (higher estimation error). The Bayes risk depends only on .
Which statement about the over-parameterized (interpolation) regime is true?
The approximation error is large, because interpolating functions are complicated.
Every interpolating function has a large test error.
Some algorithms find interpolating solutions with a small estimation error.
The test risk increases monotonically with the capacity beyond the interpolation threshold.
Explanation
In the modern regime the approximation error is about 0 and training error 0 is reached; many interpolating functions generalize badly, but some algorithms find ones that generalize well. Beyond the threshold the risk typically falls again (double descent).
In the bias-variance decomposition at a fixed point , which quantity is not affected by the randomness of a single training sample, but only by the distribution of as a whole and by ?
the bias term
the prediction
the squared error
the deviation
Explanation
The bias is a deterministic number (like the approximation error). The other three are random variables that change with the sample; the variance term is the expectation of the squared last one.
Which statement does the simple No-Free-Lunch theorem (Proposition 9) make?
Universally consistent algorithms cannot exist.
Every classifier with training error 0 has test error 0.5.
Averaged over all true functions consistent with the training data, all classifiers with training error 0 have the same error.
kNN is better than any other classifier on average over all true functions.
Explanation
The NFL is an average over all possible true functions for a fixed training set. It does not contradict universal consistency (an asymptotic statement for each fixed ), and it does not say that a single classifier has error 0.5 on a given problem.
Which mode of convergence always implies convergence in probability?
none of them, the three modes are unrelated
almost sure convergence (and also convergence)
only convergence in expectation of , i.e.
convergence in probability implies almost sure convergence
Explanation
Slide 110: a.s. ⇒ in probability and ⇒ in probability, no other implications in general. is weaker than convergence .
References
All sources cited on the slides, in slide order (7 entries)
Slide Source Key point 106 Bach Sec. 2; Devroye et al. Sec. 2; Hastie et al. Sec. 2.4-2.9 reading for the finite sample setting 113 Stone, “Consistent Nonparametric Regression”, Annals of Statistics, 1977 kNN is universally consistent 141 Belkin, Hsu, Ma and Mandal, “Reconciling modern machine-learning practice and the classical bias-variance trade-off”, PNAS 2019 double descent curve 148, 158 Ho and Pepyne, “Simple explanation of the no-free-lunch theorem and its implications”, Journal of Optimization Theory and Applications, 2002 the NFL presentation of the lecture 148 Shalev-Shwartz and Ben-David, Understanding Machine Learning, Sec. 5.1 (online) NFL, different formulation 148, 158 Devroye, Györfi and Lugosi, A Probabilistic Theory of Pattern Recognition, Chapter 7 more general NFL 158 Wolpert, “The Lack of A Priori Distinctions between Learning Algorithms”, Neural Computation, 1996 original general NFL
Related
- Previous: Lecture 1.1: Introduction and Decision Theory · Next: Lecture 2: Perceptron Mistake Bound · Course: Overview
- Concepts: Consistency, Empirical Risk Minimization, Estimation and Approximation Error, Bias-Variance Decomposition, No Free Lunch Theorem, Inductive Bias
- Exercises: Sheet 2, Exercise 2 (No Free Lunch on ), Exercise 1 (accuracy vs. loss)