Learning Theory: How Many Examples Are Enough?
PAC learning, VC dimension and uniform convergence.
Fit a model to a thousand examples and it can still fail on the next one. Learning theory turns that worry into arithmetic: it says how many examples guarantee that a good fit on the sample means a good fit on the world, and the answer depends on how many labelings a model class can produce, not on how many parameters it has.
What you’ll learn
- Define PAC learnability in the realizable and agnostic settings, and say exactly what , and "for every distribution" commit you to.
- Derive the sample complexity of a finite class: when a perfect hypothesis exists, and order when none does.
- Compute VC dimensions by exhibiting a shattered set and proving that no larger set is shattered.
- State the fundamental theorem of statistical learning, use a VC bound to estimate sample sizes, and recognize when such bounds are vacuous.
From one hypothesis to many
You train a classifier on labeled examples drawn i.i.d. from an unknown distribution , with labels , and it makes few mistakes on them. What does that say about its risk , its error rate on new data? For a single hypothesis fixed before the data arrive, the empirical risk is an average of independent coin flips with bias , and Hoeffding's inequality pins it down: .
Learning breaks that argument. Empirical risk minimization (ERM) searches a hypothesis class and returns the hypothesis with the fewest training mistakes, so the winner is chosen because it did well on these particular examples. Part of its success is luck, and luck does not carry over to new data.
A class contains 1,000 classifiers that each output a fair coin flip for every input, independently, and the 100 training labels are themselves coin flips. Every classifier has true error exactly 50%. What training error do you expect the best of the 1,000 to show?
Show the answer
0.34
Each training error is , with standard deviation . The minimum of 1,000 independent copies sits about three standard deviations below the mean: its expectation is . ERM would report a classifier that looks 66% accurate and is exactly as good as guessing. With 1,000 training examples the best of 1,000 shows about : more data shrinks the luck.
To trust ERM you need uniform convergence: with high probability, for every at once. Then whichever hypothesis ERM picks, its training error is an honest estimate of its risk. This lesson asks how large must be, as a function of , for that to hold. (Learning-theory texts often write for the sample size; this course writes .)
Probably approximately correct
Read the quantifiers one at a time. Approximately correct is the : no finite sample can pin down a classifier exactly. Probably is the : some training sets are unrepresentative (all examples from one corner of the input space, say), no learner can be blamed for those, so a small chance of failure is allowed. For every distribution makes the guarantee distribution-free: the same must work for the worst , which is why these bounds are often pessimistic for the data you actually have.
The realizable case assumes some is perfect, a strong assumption the agnostic case drops. The learner may return a hypothesis outside (improper learning). Valiant also required running time polynomial in , and the input size; the statistical question (how many examples) and the computational one (how much time) can come apart dramatically, as The Computational Hardness of Learning shows.
A learner comes with a PAC guarantee: with examples it achieves , for its class (realizable case). Which statement follows?
- On 99% of test points, the returned classifier is wrong at most 5% of the time
- If you redrew the 2,000 training examples and retrained many times, at least 99% of the returned classifiers would have error at most 5%, whatever the input distribution
- The returned classifier has error exactly 5% with probability 99%
- The returned classifier makes at most 100 mistakes on its own training set
Show the answer
B. If you redrew the 2,000 training examples and retrained many times, at least 99% of the returned classifiers would have error at most 5%, whatever the input distribution
is a probability over training sets: a small fraction of samples may mislead the learner. bounds the error of the returned classifier on the distribution. The guarantee must hold for every distribution of inputs (with labels from some in the class).
Finite classes: refuting bad hypotheses
Call bad if . Each training example independently exposes a bad with probability , so it survives all examples with probability
ERM returns some hypothesis with zero training error ( has none, so one exists). It can fail only if a bad hypothesis survives. A union bound over at most bad hypotheses gives
Make the right side at most and solve for . The class size enters only through its logarithm.
A spam filter flags an email when it contains all three words of a chosen triple, picked from a 10,000-word vocabulary, so . Suppose some triple labels every email correctly. How many labeled emails guarantee error at most 1% with probability at least 99%?
Show the answer
3045 emails
and , so : 3,045 emails. A hundred and sixty-seven billion hypotheses cost only 26 nats.
Without a perfect hypothesis, one mistake no longer refutes anything: every classifier errs sometimes, so error rates must be estimated, to precision . Hoeffding's inequality for each , combined with a union bound over the class, gives uniform convergence:
For the keyword class at , , the realizable bound asks for 609 emails and the agnostic one for 24,910: noise costs a factor of order . The logarithm also has an Occam's razor reading. If every hypothesis can be written down in bits, then and : the examples you need grow linearly with the description length of the rule you are looking for.
Infinite classes: shattering
Thresholds on the line, for , form an infinite class, yet they are easy to learn. Take the realizable case with target threshold , and let the learner put its threshold at the smallest positive training example. It errs only on , and that interval has probability above only if no training point fell into the interval of mass just to the right of , an event of probability . So suffices, with no anywhere. What matters is not how many hypotheses a class contains but how many different labelings of a sample it can produce.
| Class | VC dimension | Shattered set, and why nothing larger is |
|---|---|---|
| Thresholds on | 1 | Any single point. For the labeling is impossible. |
| Intervals | 2 | Any two points. For the labeling is impossible. |
| Axis-aligned rectangles in | 4 | A diamond of four points works. Given any five points, the bounding box of the four extreme ones (left, right, top, bottom) also covers the fifth, so "fifth point 0, rest 1" is impossible. |
| Half-spaces in | Any affinely independent points work. Radon's theorem partitions every set of points into two parts with overlapping convex hulls, and labeling the parts differently defeats every half-space. | |
| Any finite class | at most | Shattering points needs distinct hypotheses. |
| , | One parameter, yet every finite set is shattered (reveal below). |
Think first How can a class with a single real parameter shatter points for every ? Try to construct for the points , , and any labels .
Take . Then equals , plus times an even integer (the terms with ), plus with . So lies in modulo when , where the sine is positive, and in when , where it is negative. The parameter stores the labels as decimal digits: one real number can encode arbitrarily many bits.
The fundamental theorem
The growth function counts the most labelings can produce on points. It equals up to , and beyond that the Sauer–Shelah lemma (Vapnik & Chervonenkis, 1971; Sauer, 1972; Shelah, 1972) caps it: for . Exponential growth collapses to polynomial growth. The proof of uniform convergence then replaces the union bound over hypotheses by a union bound over the at most labelings of a doubled sample, so turns into roughly .
Half-spaces in have VC dimension . With examples and , how large is the gap term ?
Show the answer
0.071
Here with logarithm , so the first term is , and the confidence term is : about in total. It is guaranteed for every distribution, and it shrinks slowly: quadrupling the data to examples only brings it to about .
Suppose . Which statement is true?
- ERM fails, but a cleverer algorithm can still PAC learn
- is agnostic PAC learnable but not PAC learnable
- No algorithm PAC learns : for every sample size, some distribution with a perfect hypothesis in defeats it
- cannot fit most training sets
Show the answer
C. No algorithm PAC learns : for every sample size, some distribution with a perfect hypothesis in defeats it
The theorem makes learnability by any algorithm equivalent to finite VC dimension. The obstruction is the no-free-lunch construction (No Free Lunch & Inductive Bias): whenever shatters points, every learner given examples meets some distribution on those points, realizable by , under which its error reaches with probability at least (Shalev-Shwartz & Ben-David 2014, Corollary 6.4). Infinite VC dimension supplies such a set for every .
What the guarantees do and do not say
Two caveats keep these theorems honest. First, they are worst case over distributions: the constants and the rate must cover adversarial , so for benign data the numbers are pessimistic. Second, can be enormous. For ReLU networks with weights in layers the VC dimension is , and some such networks reach (Bartlett, Harvey, Liaw & Mehrabian, 2019). A network with a million weights trained on fifty thousand examples sits far inside , where every VC bound is vacuous, and yet such networks often generalize well. Explaining that needs complexity measures that depend on the data and on the training algorithm (Generalization in Modern ML).
| Complexity measure | Depends on | Typical gap term | Developed in |
|---|---|---|---|
| the size of the class | this lesson | ||
| VC dimension | the class, combinatorially | VC Dimension & the Fundamental Theorem | |
| Rademacher complexity, margins, norms | the class and the data | for linear predictors with , , margin | Rademacher Complexity |
| Stability, compression, PAC-Bayes | the algorithm (and a prior) | for a randomized predictor and a prior fixed before seeing the data | Stability, Compression & PAC-Bayes |
Key takeaways
- A PAC guarantee promises, for every data distribution at once, that a random training sample will fail to deliver a classifier within of perfect (realizable case) or of the best in the class (agnostic case) with probability at most .
- Finite classes need examples when a perfect hypothesis exists and for agnostic ERM: noise costs a factor , and class size enters only through its logarithm.
- Shattering measures what a class can do on finite samples: the VC dimension is the biggest sample it can label in every possible way, which half-spaces in manage for points and a one-parameter sine family for any number.
- For binary classification, learnability, uniform convergence, ERM working and finite VC dimension coincide; with noise, examples are necessary and sufficient, and without noise .
- Worst-case bounds become vacuous when is comparable to , as for large neural networks; that is what motivates data- and algorithm-dependent theories.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
In the realizable finite-class bound with , you double the number of hypotheses. How many more examples does the bound ask for?
- Twice as many
- About 69 more
- About 41% more
- None: only the VC dimension matters
Show the answer
B. About 69 more
Doubling adds to the numerator, hence examples, whatever the starting size. Sample size grows with the logarithm of the class size, that is, with the number of bits needed to name a hypothesis.
What is the VC dimension of unions of two intervals on the real line, ?
- 2
- 3
- 4
- 5
Show the answer
C. 4
Any labeling of four points has at most two runs of 1s (the worst case is or ), and each run is covered by one interval, so four points are shattered. Five points labeled have three runs of 1s, which two intervals cannot cover.
For the same finite class, why does the sample complexity grow like in the agnostic setting but only like in the realizable one?
- A noisy problem has more hypotheses to search
- ERM is no longer computable when labels are noisy
- With noise every hypothesis makes mistakes, so error rates must be estimated to accuracy , and averages of coin flips fluctuate by about
- The union bound does not apply to noisy labels
Show the answer
C. With noise every hypothesis makes mistakes, so error rates must be estimated to accuracy , and averages of coin flips fluctuate by about
In the realizable case a single training mistake eliminates a hypothesis, and a bad hypothesis is caught at rate per example. With noise, telling an error rate of from requires estimation, and Hoeffding's needs of order .
A class of binary classifiers is described by two real parameters. What can you conclude about its VC dimension?
- It is exactly 2
- It is at most 3
- It is at least 2
- Nothing in general: it can be anything from 0 to
Show the answer
D. Nothing in general: it can be anything from 0 to
VC dimension counts realizable labelings, not parameters. Half-planes through the origin in have two parameters and VC dimension 2, but has one parameter and infinite VC dimension, and a two-parameter class whose parameters do not change the predictions has VC dimension 0.
A VC bound for your trained network says its test error is at most 3.7. What should you conclude?
- The network will perform badly on new data
- Nothing about this network: a bound above 1 holds for every classifier and carries no information
- The bound must contain an arithmetic mistake
- Collecting 3.7 times more data will make the network accurate
Show the answer
B. Nothing about this network: a bound above 1 holds for every classifier and carries no information
An error rate is at most 1, so a bound of 3.7 is vacuous: true but empty. Such bounds are worst-case over all distributions and all networks in the class; they cannot certify the network, and they do not say it will fail. Data- and algorithm-dependent bounds (the Convergence lessons) can do better.
Go deeper
- VC Dimension & the Fundamental Theorem · Shattering, Sauer’s lemma and the characterization of learnability.
- Rademacher Complexity · Data-dependent bounds via symmetrization and contraction.
- Stability, Compression & PAC-Bayes · Other roads to generalization guarantees.
Further reading
- L. G. Valiant, "A theory of the learnable," Communications of the ACM 27(11), 1134–1142 (1984).
- V. N. Vapnik & A. Ya. Chervonenkis, "On the uniform convergence of relative frequencies of events to their probabilities," Theory of Probability and Its Applications 16(2), 264–280 (1971).
- A. Blumer, A. Ehrenfeucht, D. Haussler & M. K. Warmuth, "Learnability and the Vapnik–Chervonenkis dimension," Journal of the ACM 36(4), 929–965 (1989).
- S. Shalev-Shwartz & S. Ben-David, Understanding Machine Learning: From Theory to Algorithms (Cambridge University Press, 2014), chapters 2–6.
- M. Mohri, A. Rostamizadeh & A. Talwalkar, Foundations of Machine Learning, 2nd ed. (MIT Press, 2018), chapters 2–3.