Inequalities and concentration
Markov's, Chebyshev's and Hoeffding's inequalities — how far an average can stray from its mean, how many examples you need, and why the best of K models looks better than it is.
How far can an average stray
The topic Conditional expectation found the best predictor and split the variance into an explained part and noise. All of it was defined through a joint distribution that we treated as known. In practice we see a distribution only through a sample, and almost every number we report is an average: the error rate on a test set, the mean loss, a conversion rate.
Here is the setup for the whole topic. Let be independent, each with mean and variance , and let their average be
Linearity of expectation and the fact that variances of independent variables add (the topics Expectation and variance and Joint distributions and independence) give
The running example is a classifier with an unknown true error rate . On test example , let if the classifier makes a mistake and otherwise. Then with variance , and is the measured error rate.
The variance gives the typical size of the error, but not the probability of a large one. This topic asks for a bound on
when the distribution of is unknown and we know only its mean, its variance or its range. Each answer will be an inequality that holds for every distribution with that information. Each one asks for a little more information and gives a much better bound.
Markov's inequality
Start with the least information: a variable that is never negative, and its mean.
Markov's inequality. If and , then
The proof takes one line. Write for the indicator that equals when and otherwise. Since , it is always true that
When the indicator is , the left side is . When it is , the left side is . Taking expectations of both sides gives .
An example. A service's response time averages s. Then at most of requests take s or more, whatever the distribution. If the times are in fact exponential with that mean, the true share is . The bound is off by more than three orders of magnitude.
Still, it cannot be improved using the mean alone. Let with probability and otherwise: for this distribution the inequality is an equality. And nonnegativity matters. Without it, large values could be balanced by negative ones, and the mean would say nothing about the right tail.
Chebyshev's inequality
Markov's inequality ignores how spread out is. The fix is to apply it to another nonnegative variable, the squared deviation , whose mean is the variance .
The events and are the same event. Markov's inequality with gives Chebyshev's inequality:
In another form, for every .
So any distribution with finite variance puts at most of its probability two or more standard deviations from the mean, and at most three or more. For a normal distribution these shares are and . Again the worst case is far from the typical one.
Now apply the inequality to the average. Its variance is , so
Keep this line in mind; it will matter at the end of the topic. Note also how slowly it shrinks: only like . For bounded variables we can do much better.
Hoeffding's inequality
Most averages in ML are averages of bounded variables. A mistake indicator is or , a click happens or not, a loss can be clipped to . Boundedness is much stronger information than a finite variance, and it buys a bound that falls exponentially in .
Hoeffding's inequality. If are independent and every lies in , then
Here and are the ends of the range, not Markov's threshold. The variables need not have the same distribution; they must be independent and bounded. The width plays the role of the spread.
Compare the bounds on a fair coin. Toss it times: how likely is the share of heads to be off by at least ? Here , so Chebyshev gives , and Hoeffding with gives . The exact probability comes from the binomial distribution.
| Chebyshev | Hoeffding | Exact | |
|---|---|---|---|
At Hoeffding even loses to Chebyshev. At Chebyshev is off by a factor of about , while Hoeffding is within a factor of . As soon as is large, the exponential wins.
How many examples you need
Now turn the question around. How many examples do we need for the measured error rate to be within of the truth with probability at least ? Set a bound equal to and solve for .
Chebyshev gives , and for a variable . Hoeffding with requires , which gives
For a margin of with probability ():
| Method | Examples | Assumes |
|---|---|---|
| Chebyshev, | finite variance | |
| Hoeffding | independent, bounded | |
| Normal approximation | large |
The last row comes from the central limit theorem, two topics ahead. It is an approximation, not a guarantee.
The two guarantees differ most in how they depend on . Chebyshev's grows like , Hoeffding's like . At Chebyshev asks for examples and Hoeffding for .
Where the exponent comes from
Where does Hoeffding's exponential come from? It is Markov's inequality again, applied to an exponential. This argument is called the Chernoff method.
Let , so that the upper deviation is the event . For any the function is increasing, so this is the same event as . The variable is nonnegative, and Markov's inequality gives
As a function of , an expectation like is called the moment generating function. For independent variables the expectation of a product is the product of expectations, so
Each factor is bounded by Hoeffding's lemma, which we take without proof: if , then
Putting the pieces together, for every ,
The left side does not depend on , so we are free to pick the that makes the exponent smallest. That choice gives exactly . The lower tail is handled the same way, and the union bound from Kolmogorov's axioms adds the two tails, which is where the factor comes from.
So all three inequalities are one idea: Markov's inequality applied to , to and to . The more of the function sees, the tighter the bound. Boundedness is what makes the exponent quadratic in .
The best of K models
Back to the classifier. Write for the true error rate of a classifier , and for its error rate on a validation set of examples. If is fixed before we look at the validation data, is an average of indicators, and Hoeffding gives
In practice we try models (architectures, hyperparameters, checkpoints) and keep the one with the lowest validation error. The winner was chosen by the validation data, so the bound for a fixed model does not apply to it. The way out is a bound that holds for all models at once. The union bound from Kolmogorov's axioms gives
Set the right side equal to and solve for . With probability at least , simultaneously for all models,
This is a first generalization bound. With , and the margin is about . The number of models enters only through : a thousand candidates widen the margin by a factor of about compared with a single model.
The other side of the coin is the selection effect. Suppose all models have true accuracy exactly , and each is scored on examples with independent noise. The best measured accuracy then averages about : more than a point of pure luck. The best of many looks better than it is. That is why the final model is reported on a held-out test set that played no part in the choice.
What comes next
Each inequality in this topic trades information for strength:
| What we know | Inequality | How the bound for falls |
|---|---|---|
| and the mean | Markov | gains nothing from |
| the variance | Chebyshev | like |
| independent, bounded | Hoeffding | like |
They have limits. All of them are worst-case bounds. Heavy tails break Hoeffding; there one uses robust estimates such as the median of means. Dependent data, like frames of a video or a time series, call for block methods. When the variance is small relative to the range, Bernstein's inequality is sharper. The union bound ignores how similar the candidates are, so the real selection effect is often smaller. And infinite model classes need measures of capacity, which belong to learning theory.
Now look once more at the Chebyshev bound for the average, , and ask what it does as grows with fixed. The answer is the statement that averages settle down around the mean. The next topic, The law of large numbers, proves its weak form with exactly this line, states the strong form, and reads the empirical risk of a model as a sample mean.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Answers are saved on the server and tied to this browser until you sign in.