A classifier makes 120 mistakes on 1,000 labeled examples, so its empirical error rate is 0.12. How large could its error rate be on new cases from the same population? The observed score is one number computed from one sample, while a guarantee about risk is a theorem that holds only under stated assumptions. This lesson derives one such theorem for a finite set of candidate predictors, computes what it promises, and shows which conditions a project must meet before the promise applies.
Key terms
Finite hypothesis class
Definition A hypothesis class is the set of predictors that a learning procedure is allowed to choose from. It is finite when it has finitely many members, and denotes their number. The guarantees on this page assume the following setting. The examples are independent draws from one distribution , the population whose risk we want to describe. The loss satisfies for every possible target and prediction. The class is fixed before the sample is drawn, so it does not depend on these examples. For each in the population risk and the empirical risk are
where is a new draw from . The gap of is . Its value depends on the random sample.
In plain words The class is the menu of predictors. The theorems below say nothing until three things hold, a menu written down before the data arrive, losses that can never exceed one, and examples drawn independently from the population we care about. Zero-one loss, which charges 1 for a wrong label and 0 for a right one, meets the boundedness condition. Squared error on an unbounded target does not, even when every observed error happens to be small.
Example For a constructed task of flagging late deliveries, take the twenty rules “flag the delivery when its distance exceeds km” for , chosen before any data are seen. They form a finite class with . Under zero-one loss, a rule that makes 120 mistakes on 1,000 examples has empirical risk 0.12. Its population risk is the probability that it errs on a new delivery drawn from , a fixed number that the sample does not reveal. The rules with every real threshold form an infinite class, although each rule is described by a single number.
Hoeffding’s inequality
Definition Let be independent random variables with for every , where are constants, and let be their average. Hoeffding’s inequality states that for every
For one predictor fixed before the sample is drawn, the losses are independent, lie in and have mean , so
The probability is over the random sample, and the factor 2 covers deviations in both directions. The inequality uses only independence and the range of the losses, so it holds for every distribution . The same generality makes it loose for many particular distributions. It applies to a predictor fixed in advance. A predictor chosen because its empirical risk is small depends on the sample, and the inequality does not apply to it directly.
In plain words An average of many independent bounded quantities rarely strays far from its mean, and the chance of a large deviation shrinks exponentially as grows. Bounded losses keep any one example from moving the average by more than .
Example For and the bound is . So if one classifier was fixed before the 1,000 examples were drawn, the chance that its empirical error differs from its population error by 0.05 or more is at most about 0.0135. With only examples the same gives , a bound above 1 that says nothing.
Union bound and uniform convergence
Definition The union bound states that for any events
with no assumption of independence. A class has the uniform convergence property for a loss when, for every and every in , there is a sample size such that for every and every distribution , a sample of independent draws from gives with probability at least . In the setting above, apply the union bound to the events , one for each member, and bound each by Hoeffding’s inequality.
So every finite class with losses in has the property, and any works.
In plain words Each member of the class has a small chance of a misleading score. The union bound adds those chances, so the chance that at least one member is misleading is at most the total. Adding is valid however the events overlap, and it is wasteful when they overlap a lot, as they do for similar predictors. The payoff is a statement about every member at once, so it still holds for whichever member the data end up choosing.
Example With and , each fixed classifier has failure probability at most . For 20 classifiers the union bound gives at most . For 2,000 classifiers it gives , which is above 1 and says nothing at this . If two classifiers in the class give identical predictions, their failure events are the same event, yet the union bound counts its probability twice.
Generalization bound
Definition A generalization bound limits the population risk of a learned predictor by quantities computed from the training sample, with a stated probability over the draw of that sample. For a finite class the derivation above gives the following theorem. Suppose the class is fixed before the sample is drawn, the examples are independent draws from , the loss takes values in and is in . Setting and solving gives
with the natural logarithm. Then, with probability at least , every in satisfies . Because this event covers every member, it covers a member chosen with the same sample. If minimizes the empirical risk over and minimizes the population risk over , both of which exist because the class is finite, then on the same event
The first and last steps use the uniform event, and the middle step holds because has the smallest empirical risk. The theorem says nothing about how good is, and it can be loose, since Hoeffding’s inequality ignores the actual spread of the losses and the union bound ignores overlap between members.
In plain words Before the sample is drawn, there is a probability of at least that every member’s score will land within of its risk. After one sample the event has either happened or not, and we cannot tell which. The radius depends on the class size only through a logarithm under the square root, shrinks in proportion to , and grows when is made smaller. Those are properties of this formula, not predictions of how a particular model’s error will behave.
Example Take and . For , the quantity is 800, its logarithm is about 6.6846, and dividing by 2,000 and taking the square root gives .
| Class size | ||
|---|---|---|
A member of the 20-rule class selected with empirical risk 0.12 therefore has population risk between about 0.0622 and 0.1778 on the uniform event, and the empirical risk minimizer is within of the best rule in the class. A class 100 times larger adds only to the logarithm. Quadrupling the sample to 4,000 halves the radius to about 0.0289. The bound is also loose. For a single fixed classifier with true error rate 0.12 and , the exact binomial probability of a gap of 0.0429 or more is about 0.00004, far below the 0.05 that the bound allows.
Capacity
Definition Capacity describes how rich a hypothesis class is, how many different patterns of predictions its members can produce, and therefore how easily some member can match a sample by chance. No single measure applies to every class. In the finite-class bound the measure is , the logarithm of the number of distinct predictors. The number of parameters is a different quantity. A class indexed by even one real-valued parameter usually contains infinitely many predictors, so the finite-class bound gives no conclusion about it, and infinite classes need other capacity measures, such as the VC dimension, each with its own theorem and assumptions. Two rules follow from the derivation. Replacing by any number keeps the bound valid, because increases with the class size. And the class must contain every predictor the whole procedure could have returned, across every candidate model, hyperparameter setting and feature subset the data might have led to, all fixed before the sample is drawn. Counting only the candidates a search happened to try is not enough, and an adaptive search over networks with real-valued weights can reach infinitely many predictors.
In plain words A richer class has more ways to match the training sample by luck, so its training scores need a wider allowance. The allowance depends on what the class can express, not on how many numbers describe one member. Capacity is neither good nor bad by itself. A class with too little of it may not contain any good predictor.
Example A linear classifier with ten real-valued coefficients on real-valued features defines infinitely many classifiers, not ten. Suppose instead that each coefficient is restricted, before any data are seen, to a grid of 1,000 values. The class then has at most members, and with and
Substituting , the number of parameters, would give about 0.0547, a radius that the theorem does not support.
Inductive bias and the no free lunch theorem
Definition The inductive bias of a learning procedure is the set of assumptions or preferences, beyond the training data, that leads it to favor some predictors over others that fit the same data equally well. It enters through the class, such as linear functions, through penalties, such as the ridge preference for small weights, and through built-in structure, such as smoothness or the sharing of weights across positions in an image model. The no free lunch theorem shows that some bias is unavoidable. One version concerns a finite input set , labels in and zero-one loss. If the target function is drawn uniformly from all functions from to , then for every learning algorithm whose internal randomness is independent of , and any training inputs chosen independently of and labeled by , the predicted label at any input outside the training inputs is correct with probability exactly . Averaged over all targets, every algorithm therefore has the same error on unseen inputs, , so an advantage on some targets is exactly offset on others. Another version, in the same binary setting, shows that for every algorithm and every training size below half the number of possible inputs, some distribution has a predictor with zero risk while the algorithm’s risk is at least with probability at least over the sample.
In plain words Data say nothing by themselves about inputs that were never observed, so some assumption has to connect seen and unseen cases. The theorem averages over every conceivable labeling, including labelings with no pattern at all, and real problems are not like that. It does not say that learning is futile. It says that a procedure works because its assumptions suit the problem. The generalization bound controls how far the chosen member falls behind the best member of the class, and only the fit between the bias and the problem decides whether that best member is any good.
Example Suppose there are two inputs and the training set shows label 1 at the first. A world with label 1 at the second input and a world with label 0 there agree with everything observed. A learner that assumes nearby inputs share labels predicts 1, and it is right in the first world and wrong in the second. Too strong a bias fails in a different way. The class of the two constant classifiers has , and with and its radius is about 0.0468. If the feature is uniform on and the label is 1 exactly when the feature is at least 0.5, both constants have risk 0.5, while the threshold rule at 0.5 has risk 0. The bound is narrow around a poor answer.
Check yourself
- Five prespecified classifiers are scored on 400 independent examples with zero-one loss, and . The classifier with the smallest empirical error, 0.08, is selected. Compute and the upper bound on the selected classifier’s population error rate. Does the bound apply although the classifier was chosen with the same data?
Show the answer
The quantity is , and . Dividing by gives about 0.005756, and the square root is . With probability at least 0.9 over the sample, all five classifiers have gaps of at most simultaneously, so the selected one has population error rate at most
The bound does apply. The uniform event covers all five members, so it does not matter which one the data picked. It would not apply if the five candidates had been chosen after looking at these 400 examples, or if more than five candidates had been tried and only five counted.
- A team has 1,000 prespecified rules and wants every gap to be at most 0.05 with . How many independent examples does the finite-class theorem require? What does it then guarantee about the rule with the smallest empirical risk, compared with the best rule in the class? How many examples would a radius of 0.025 require?
Show the answer
The condition is equivalent to
since and its logarithm is about 12.206. So the theorem needs at least 2,442 examples. With probability at least 0.99, every rule is then within 0.05 of its risk, and the empirical risk minimizer has population risk at most above that of the best rule in the class. Halving the radius multiplies the requirement by four, which gives , so at least 9,765 examples.
- A colleague fits a linear demand forecaster with ten real-valued coefficients to 400 consecutive days of sales. To quote a guarantee, they divide every squared error by the largest squared error in the sample so that the losses lie in , set and , and call the result a 95 percent guarantee for next month’s squared error. Which conditions of the finite-class theorem fail?
Show the answer
Several conditions fail, and any one of them is enough to void the claim.
The class is not finite with ten members. Ten real-valued coefficients define infinitely many forecasters, and the fitted coefficients were chosen from all of them, so the number of parameters cannot stand in for and the finite-class bound gives no conclusion.
The loss is not bounded by a constant fixed in advance. Raw squared errors have no upper limit, and a scale taken from the sample after seeing it does not make the loss bounded on new days, since a future error can exceed the largest one observed. The rescaled number is also not the squared error the colleague wants to describe.
The days are not independent draws from one distribution. Consecutive days are correlated, demand drifts, and next month is a different population from the 400 days used.
An honest report would instead evaluate the forecaster on later days that played no part in fitting or choosing it, with a time-ordered split, and state that the result describes those days. A guarantee would need a theorem built for dependent data, a loss bounded by a constant chosen before the data were seen and a class whose capacity is measured correctly.