PAC Learning & VC Dimension
How do we know a learner will generalise before we ever see a test set? PAC theory turns "it works on the training data" into a quantitative promise: version spaces, Haussler's bound, sample complexity, the agnostic Hoeffding bound, and the VC dimension that measures capacity when the hypothesis space is infinite — ending in structural risk minimisation.
01 · Motivation
Why does this matter?
In Chapters 2–4 you trained models and used cross-validation to estimate their generalisation error. That works in practice, but it leaves a deep question untouched: can we prove, before we even look at a test set, that a learner will generalise? And if so, how much data is enough to make that proof trustworthy?
Three concrete pains that PAC theory addresses.
It overfits — but why?
You saw in Ch. 4 that a model with low training error can still fail on new data. PAC theory turns this from a mystery into an inequality: training error is a biased estimator of true error, and the bias is controlled by how rich your hypothesis space is relative to how many examples you saw.
How many samples do I need?
Before collecting (or labelling) data, a working engineer wants a budget: “to be sure my classifier has error under , how many labelled examples do I need?” PAC gives a closed-form answer — and it is surprisingly modest for finite hypothesis spaces.
Which model class is even learnable?
Not every concept can be learned from a polynomial number of examples. PAC-learnability is a precise yes/no notion that separates the tractable from the impossible — and it is the gateway to the deeper question of capacity measured by VC dimension.
The whole chapter in one sentence
If your hypothesis space is not too rich relative to the amount of data you have, then any hypothesis that fits the training set will, with high probability, generalise. Everything below — version spaces, Haussler’s bound, VC dimension, SRM — is the precise statement of “not too rich” and “high probability”.
PAC sits at a different level from Chapters 2–3, which were about algorithms. This chapter is about guarantees. The tools we build here (capacity, sample complexity, generalisation bounds) are what justify the regularisation in Ch. 2/4, the max-margin principle in Ch. 7, and the kernel trick in Ch. 6. You can do ML without it. You can’t understand why ML works without it.
02 · Intuition
The idea in plain language
Picture the space of all hypotheses your learner could possibly output as a city. Among them, somewhere, is the true concept — the function nature uses to label data. Around is a small neighbourhood of “good” hypotheses with error below your tolerance . The rest of the city is “-bad”: hypotheses whose error is at least .
When you train, you observe labelled examples drawn independently from some unknown distribution . The version space is the set of hypotheses in that label every training example correctly. The learner picks one of them. But the version space is not the same as the set of good hypotheses: it may contain hypotheses that happen to fit the training data while being secretly bad off-training.
The whole game is: how likely is it that the version space is “poisoned” by an -bad hypothesis? If we can make that probability tiny, then any hypothesis we pick from is, with high confidence, good.
The two knobs of PAC
A PAC guarantee has two parameters and they mean different things:
- (accuracy) — the largest error we tolerate. “Approximately correct.”
- (confidence) — the probability we’re allowed to fail outright. “Probably.”
We never get a deterministic promise. We get: with probability at least over the random training set, the learner outputs a hypothesis whose true error is at most . Both knobs cost data — but only logarithmically in and linearly in , which is why PAC works at all.
Why bad hypotheses can survive training
Here is the heart of the argument, stripped to one image. Suppose a specific hypothesis has true error — it disagrees with the target on a fraction of inputs. What is the probability that random inputs all happen to fall in the agreement region? It’s . For and , that’s about — small, but not negligible. With such bad hypotheses, the expected number that “fool” the training set is , and the version space is full of impostors.
The fix is to make large enough that becomes tiny. Solving for gives the famous PAC sample-complexity formula. The next section makes this rigorous.
”Linear” but in capacity
The same bias–variance dial that haunted us in Ch. 4 reappears here, written in the language of .
Big H → low bias, high variance
A rich hypothesis space probably contains a hypothesis close to the target — bias is small. But many hypotheses can also accidentally fit the training data — the version space is large, full of -bad impostors. High capacity demands more data.
Small H → high bias, low variance
A small hypothesis space might not even contain the target — bias may be irreducible. But there are few candidates that could accidentally fit the data, so the bound is tight. Less capacity, less data.
PAC turns “rich enough but not too rich” from a vibe into a number.
03 · Formalism
Definitions and equations
Time to nail down the symbols. Everything in this chapter rests on this small notation set — invest the minute to memorise it.
The PAC setup
- X
- the instance space — all possible inputs (e.g. all binary feature vectors of length ).
- P
- an unknown, fixed distribution over from which inputs are drawn. The learner never sees , only samples.
- C
- the concept class — the family of true Boolean functions we might face.
- c ∈ C
- the actual target concept the data was labelled with.
- H
- the hypothesis space — the family of functions the learner is allowed to consider. Often , but not always.
- D
- the training set: i.i.d. pairs with .
- L_true(h)
- the true error . What we actually care about.
- L_train(h)
- the training error — the fraction of on which disagrees with .
- ε
- accuracy tolerance, . We want .
- δ
- confidence parameter, . We allow ourselves to fail with probability .
The version space
The set of hypotheses that classify every training example correctly. In the realisable setting (where some achieves zero true error), is never empty — itself is always inside.
A version space is -exhausted if every hypothesis still alive in it has true error below . That’s the property we want: if is -exhausted, any consistent hypothesis is automatically good.
Haussler’s theorem (finite H, realisable case)
Haussler 1988
Let be finite and a sequence of i.i.d. examples of some target concept . For any ,
In words: the probability that some -bad hypothesis survives examples shrinks exponentially in and grows only linearly in .
Proof in three lines (an exam favourite)
1 · One bad hypothesis
Fix a specific -bad hypothesis (i.e. ). The probability it agrees with one random example is at most . For i.i.d. examples it agrees on all of them with probability at most
Why and not ? Because may exceed , making agreement even less likely.
2 · Union bound over H
There are at most bad hypotheses to worry about. By the union bound,
3 · The exponential inequality
Use the standard inequality (valid for all ):
That’s the bound. Three lines, two ideas, one inequality.
From bound to sample size
Set the right-hand side to and solve for .
Read this carefully. The cost of better accuracy is (linear). The cost of more confidence is (logarithmic — confidence is cheap!). The cost of a richer hypothesis space is — also logarithmic, so doubling costs just one more example per accuracy unit.
The same inequality solved for given and gives the generalisation bound form:
A concrete count: conjunctions of literals
Consider Boolean attributes and let be the set of conjunctions where each literal is either present positively, present negatively, or absent. That’s choices per attribute, so
Linear in the number of attributes. Even with features, , , we need only labelled examples. That is why ML works.
Why we cannot let H be 'all Boolean functions'
A function from to is specified by its truth table on inputs. There are such functions, so
Sample complexity becomes exponential in the number of features. For features that’s a billion examples to learn a generic Boolean function with PAC guarantees. This is the precise reason ML must commit to an inductive bias — a restricted hypothesis class — before seeing the data. Without it, learning is doomed.
PAC-learnability, formally
PAC-learnable concept class
A concept class is PAC-learnable by learner using hypothesis space if there exists an algorithm such that for every , every distribution over , every , and every , with probability at least outputs a hypothesis with , using a number of samples polynomial in and .
It is efficiently PAC-learnable if, additionally, the learner’s running time is polynomial in , , the input size , and .
When the version space is empty: agnostic PAC
In real life, no hypothesis in is perfect — there is always irreducible label noise, model misspecification, or both. The version space collapses to . We no longer ask for ; we ask: given that we picked the hypothesis with smallest , how far can be from ?
The tool is Hoeffding’s inequality, a concentration result that says: the empirical mean of bounded i.i.d. random variables is, with high probability, close to the true mean. For us, “empirical mean” is training error and “true mean” is true error — exactly what we need.
Hoeffding's inequality (one- and two-sided)
Let be i.i.d. random variables with , and let . Then for any ,
The two-sided form (right) is what we use when we don’t know which way the gap will fall. Either way, the bound is exponential in — the price of getting “twice as close” is “four times the data”.
How does this apply to a classifier ? Set — the indicator that makes a mistake on the -th training example. Then and . Hoeffding tells us that for any single , the training error is a tight estimate of the true error. Apply it to each and union-bound over :
Note the square on — agnostic learning needs more data than the realisable case for the same accuracy, because we now have to estimate every from instead of just ruling out impostors.
Setting the right side to and solving gives the generalisation form that the exam expects you to know by heart.
The bias–variance trade-off Ch. 4 promised, now written as a bound. Big — small training error (good bias term) but large square-root term (large variance). Small — flipped. The trade-off lives inside the inequality.
What if H is infinite?
Everything above used as the capacity measure. For continuous hypothesis spaces — lines in , all polynomials of bounded degree, neural networks — , and is undefined. The bound becomes vacuous.
But this cannot be the right answer. We routinely learn with linear classifiers from finite data and they generalise. The issue is that is the wrong measure: most of the “different” hypotheses in a continuous family agree on almost every point. What matters is not how many hypotheses there are but how many distinct labellings of finite samples the family can produce. That number is what the VC dimension captures — §05 of this chapter. Hold that thought.
04 · Worked example
How many labelled examples does my spam filter need?
Let’s make every symbol concrete with a problem you might actually face. You’re building a spam classifier whose hypothesis space is conjunctions of literals over boolean features (e.g. “the word discount appears AND the sender is unknown AND the subject is in ALL CAPS”). You want to be sure the true error is below . How many labelled emails do you need to collect?
Step 1 · Translate the requirements into PAC parameters
| Requirement | Symbol | Value |
|---|---|---|
| True error tolerance | 0.05 | |
| Failure probability | 0.01 | |
| Number of features | 20 | |
| Hypothesis count |
Three choices per feature: positive, negative, or absent (= the literal “doesn’t matter”). With twenty features, three and a half billion possible conjunctions.
Step 2 · Plug into the realisable sample-complexity formula
2a · The formula and its assumption
Recall:
We use this only if we believe there exists with . For a spam filter with twenty hand-engineered binary features, this is plausible on a clean training set.
2b · Compute the log term
And .
2c · Add and divide by ε
labelled emails. Surprisingly few.
Step 3 · Feel the scaling
Pause to appreciate how cheap the parameters are.
| Change | New | Cost factor |
|---|---|---|
| Baseline () | 532 | 1× |
| Want (5× more accurate) | 2 658 | 5× (linear in ) |
| Want (10 000× more confident) | 716 | 1.35× (log!) |
| Double the features () | 971 | 1.83× (linear in ) |
| Switch to arbitrary Boolean functions () | 40 000× (exponential) |
The last row is the punchline. Allowing any Boolean function as a hypothesis pushes the sample budget into the tens of millions — humans cannot label that many emails. The inductive bias of “conjunction of literals” is what makes the problem learnable. This is PAC’s quantitative answer to “why do we need priors / regularisation / a restricted hypothesis class?”.
Step 4 · What if the data is noisy?
Suppose your training set is not perfectly clean — maybe of labels are wrong, so no conjunction will have zero training error. Switch to the agnostic bound. We want with and :
Ten times the realisable case — because appears squared. The price of noise-robustness is paid in data.
What just happened, in three bullets
- The hypothesis space is huge ( conjunctions) yet only matters — that’s the magic of logarithm.
- Confidence is cheap, accuracy is expensive. 10 000× lower needs 35% more data; 5× lower needs 5× more data.
- Bias matters. Restricting to conjunctions cuts sample complexity by four orders of magnitude vs unrestricted Boolean functions. Without an inductive bias, learning is impossible from realistic samples.
05 · Visual explanation
Seeing it geometrically
Three pictures that capture the geometry of PAC and VC. Make space for them in your head — they generalise immediately to every later chapter that talks about capacity.
A · Learning axis-aligned rectangles
The cleanest concrete PAC example. The target concept is an axis-aligned rectangle in the plane; points inside it are positive, outside are negative. Our learner outputs the tightest rectangle around the positive training examples — a sensible, consistent strategy.
The error region (orange stripes) is the part of the true rectangle that the learner’s tighter misses: positive points there would be wrongly classified as negative. Decompose this ring into four strips — top, bottom, left, right. If we guarantee each strip has probability mass at most , the total error is at most .
For any strip individually: the probability that no training point lands in it is . Apply the union bound over four strips and the standard inequality.
1 · Over-allocate the budget
The error region is the union of (at most) four rectangular strips — top, bottom, left, right. We over-allocate budget: ask each strip to carry probability mass at most . If all four succeed, the total error is at most .
2 · The bad event for one strip
A bad event for one strip: its probability mass is yet no training point landed in it (otherwise would have stretched to include that point). The probability of “no points in a region of mass ” is .
3 · Union-bound the four strips
Union-bound over the four strips: . Force this to be and use :
Notice: the bound depends on and but not on — which is infinite here. Geometry replaced finite enumeration. That’s the seed of the VC argument.
B · Shattering — what capacity really means
Forget “how many hypotheses are there?” and ask instead: “on a given set of points, how many different label patterns can my hypothesis class realise?” A class shatters a set of points if it can realise all possible -labellings of those points.
For 3 collinear points with a 1-D threshold classifier, only 4 of the 8 labellings are realisable (the four monotone ones). 1-D thresholds cannot shatter 3 points. But linear classifiers in 2-D can shatter 3 (non-collinear) points — all eight labellings, shown below; the XOR pattern on 4 points is the configuration no line can split:
The “XOR” pattern on the corners of a square is not linearly separable. Hence 2-D linear classifiers cannot shatter this set of 4 points — and indeed they cannot shatter any set of 4 points. The VC dimension of 2-D linear classifiers is therefore 3.
VC dimension in plain English
The VC dimension is the size of the largest set of points that can shatter. Showing means exhibiting some arrangement of points that shatters. Showing means proving that every arrangement of points has at least one labelling cannot produce. Asymmetric, on purpose.
C · The VC generalisation bound
With VC dimension as the right capacity measure, the agnostic bound generalises to infinite hypothesis classes.
Replace with a term that grows linearly in (with a log factor). The shape of the bound — empirical risk plus a capacity-dependent penalty — is exactly the bias–variance picture, and it is the principle behind structural risk minimisation: choose (out of a ladder of nested spaces) so the right-hand side is smallest.
As VC dimension grows, training error decreases (the model can fit more) but the penalty grows. The sweet spot — minimum of the sum — is the classifier you should pick. That is SRM, and you can feel it move in Hands-on 3’s companion intuition below.
D · From VC bound to sample complexity
Solving the VC bound for (the analogue of what we did with Haussler in §03) gives the VC sample-complexity formula — the number of examples sufficient to guarantee error at most with probability at least , for an infinite hypothesis class of VC dimension :
Same shape as the finite- formula: linear in (up to a log), logarithmic in , and now linear in instead of . VC dimension is the right capacity measure: it plays the role that played for finite spaces.
E · Two structural theorems about VC dimension
VC vs. log of hypothesis-space size
For any finite hypothesis space, .
Proof (one line): if , there exists a set of points that shatters — i.e. realises all labellings on those points. Each labelling requires a distinct , so , i.e. .
Infinite VC ⟹ not PAC-learnable
A concept class with is not PAC-learnable. Intuition: if every finite sample size admits some configuration of points that can shatter, then no algorithm using examples can rule out all -bad concepts — an adversary can always hide a bad target in the unshattered direction. Finite VC is the price of admission to PAC-learnability.
06 · Hands-on
Try it yourself
Three labs, each tuned to drill in one PAC/VC concept that has to be felt moving before it sticks. Push the sliders, drag the points, watch the numbers, then read the takeaway.
Sample-complexity calculator
Pick accuracy ε, confidence 1−δ, and the hypothesis-space size |H| = 3^M (conjunctions of literals over M features). The calculator reports the minimum N for the realisable PAC bound and the agnostic (Hoeffding) bound.
Watch the version space shrink
The target is the green interval. Each sample lands inside (positive, +) or outside (negative). The version space — every interval consistent with all samples — is bracketed by the tightest consistent interval (gold) and the loosest (dashed). Watch it collapse toward the truth.
Shattering check — drag the points
Three points in 2-D. Cycle through all 2³ = 8 possible ±-labellings; for each, a perceptron searches for a separating line. Drag a point to move it. As long as the three are in general position (not collinear), every labelling is realisable — that is what shattering looks like, and it proves VC ≥ 3 for lines in the plane.
07 · Exam intel
What the exam actually tests
PAC and VC questions are short and structured — they’re the theoretical block of a Polimi ML exam. Five archetypes appear essentially every year.
Derive Haussler's bound from scratch
Start by fixing a single -bad hypothesis. Show . Union-bound over at most such hypotheses to get . Finish with the inequality to obtain . Three steps, name each one, full marks.
Compute a sample-complexity bound
“Given , , , how many samples does PAC guarantee?” Apply (realisable) or (agnostic). Watch which one is asked — the squared is the agnostic signature.
Compute the VC dimension of a given class
Standard arguments expected at exam:
| Hypothesis class | VC | Reasoning |
|---|---|---|
| 1-D thresholds | 1 | Can shatter 1 point, not 2 (can’t realise ). |
| 1-D intervals | 2 | Two points: all four labellings; three points: can’t realise . |
| Linear classifier in | Hyperplane has parameters; general-position points are shatterable. | |
| Axis-aligned rectangles in | 4 | Four points on a diamond shatterable; any five — one labelling fails. |
| Neural network with parameters | Roughly linear in parameter count for most activations. | |
| 1-Nearest Neighbour | Can memorise any finite labelled set. | |
| Gaussian-kernel SVM | Infinite-dim feature space — but effective capacity is controlled by margin. |
Full-mark answers prove both (exhibit a shatterable set) and (show some labelling of every -set is unrealisable).
State the VC generalisation bound and SRM
Memorise both forms:
Then articulate SRM in one sentence: “Among a nested ladder of hypothesis spaces , pick the one that minimises the right-hand side, not just the training error.” This is the principled cousin of cross-validation. Be ready to add the two structural facts: for finite , and rules out PAC-learnability.
Connect PAC bounds to the bias–variance picture
Be ready to point at the agnostic bound and identify: bias term (small for large , large for small ); the or VC penalty variance term (the opposite). The trade-off sits inside the inequality. The “right” minimises the sum, which is exactly what Ch. 4’s cross-validation does empirically and SRM does analytically.
Formulas to memorise verbatim
- Version space: .
- Haussler: .
- Realisable PAC: .
- Hoeffding (two-sided): .
- Agnostic PAC: .
- VC sample complexity: .
- when is finite; not PAC-learnable.
08 · Common mistakes
Where students get this wrong
'PAC says my classifier has error ≤ ε'
It says no such thing. PAC is a statement about probability: with probability over the choice of training set, the learner’s output has error . The remaining probability mass is unlucky training draws on which the learner can fail arbitrarily. There is no deterministic guarantee — there can’t be, since with tiny probability you could draw the same example times.
Confusing 'VC ≥ d' with 'VC = d'
To show you need to find one set of points that shatters. To show you need to prove that every set of points has at least one labelling cannot realise. The two halves are very different in spirit; a complete VC argument does both.
'VC dimension = number of parameters'
A useful heuristic — true for linear classifiers ( parameters), neural nets (). But not a law. Two concrete counter-examples from the slides:
- One parameter, infinite VC. The class on has a single parameter , but by choosing extremely large you can realise any binary labelling of any finite set of points along the real line. with just one knob.
- Infinitely many parameters, finite effective capacity. An SVM with a Gaussian kernel implicitly works in an infinite-dimensional feature space — its formal VC dimension is — yet with margin regularisation it generalises beautifully. The margin controls effective capacity, not parameter count.
Moral: parameter count is a rough proxy. The right capacity measure depends on the geometry of the hypothesis class and the loss — VC for 0/1 loss, Rademacher complexity in general, margin-based bounds for kernel methods.
Using the realisable bound when L_train > 0
The bound requires the existence of a hypothesis with zero training error (and assumes the learner picks one). If your best hypothesis has 8% training error, you are in the agnostic regime and must use the Hoeffding-based bound — which pays an extra in sample complexity. Quoting the realisable formula in a noisy setting is a hallmark exam-time mistake.
'The bound is loose, so PAC is useless'
PAC bounds are notoriously loose numerically — they often predict needing 10× more data than works in practice. That’s because they are worst-case over all distributions and all targets , with no distributional assumptions. The shape of the bound (logarithm in and , linear in , , or VC) is what we actually use — it tells us what to regularise, why bigger models need more data, and where SRM comes from.
Forgetting the i.i.d. assumption
Every bound in this chapter assumes training samples are drawn independently from the same distribution that will generate test data. If your data is time-series, or stratified, or comes from a different distribution at test time, none of these guarantees apply. Bounds for non-i.i.d. settings (online learning, domain adaptation) exist but are outside this chapter — and they are typically much weaker.
'Infinite VC means cannot learn'
Infinite VC means the worst-case PAC bound is vacuous, but it does not mean the algorithm can’t generalise on real problems. SVMs with Gaussian kernels have infinite VC and are world-class classifiers — because their effective capacity is controlled by the margin, regularisation, and data geometry. VC is one capacity notion; Rademacher complexity and margin-based bounds are others. Don’t conflate “infinite VC” with “doesn’t work”.
09 · Self-check
Can you answer these?
Five questions in the style the chapter typically gets tested. Click an option for instant feedback.
In the realisable PAC setting with finite |H|, how many examples are sufficient to guarantee with probability at least 1−δ that any consistent hypothesis has true error at most ε?
The version space VS_{H,D} is...
What is the VC dimension of the class of linear classifiers in ℝ^M (with bias term)?
You enlarge your hypothesis space from H₁ (|H₁| = 100) to H₂ (|H₂| = 10⁶). Holding N, δ, and the best in-class training error fixed, what happens to the agnostic bound L_true ≤ L_train + √((ln|H| + ln(1/δ))/2N)?
A hypothesis class H shatters a set S = {x₁, x₂, x₃, x₄} of four points. Which consequence is most accurate?
10 · Recap
One-screen summary
Chapter 05 — load-bearing ideas
- PAC framework. i.i.d. samples , unknown target , hypothesis space , and two knobs: accuracy and confidence . We want with probability .
- Version space . Hypotheses consistent with . Bad hypotheses can survive — Haussler bounds how often.
- Haussler’s bound. . Three-line proof: per bad , union-bound, .
- Realisable sample complexity. . Linear in , log in capacity and . Confidence is cheap.
- Hoeffding inequality. For i.i.d. : . Setting links it to and .
- Agnostic bound. . Squared — noise costs data: agnostic sample complexity is instead of .
- Bias–variance, baked in. Big : small (low bias) but penalty large (high variance). Small : reversed. The right minimises the sum.
- Inductive bias is mandatory. Unrestricted Boolean functions give , so scales like — exponential. Restricted classes (conjunctions, half-spaces, …) make learning possible.
- Shattering & VC dimension. shatters iff all labellings of are realisable. = size of largest shatterable set. For finite , .
- VC of canonical classes. 1-D thresholds: 1. 1-D intervals: 2. Linear classifiers in : . Axis-aligned rectangles in : 4. 1-NN and Gaussian-kernel SVM: .
- VC generalisation bound. . VC sample complexity: . Infinite VC ⟹ not PAC-learnable.
- Structural Risk Minimisation. Among nested , pick the one minimising the VC bound. Principled regularisation; the theoretical sibling of cross-validation.
Looking ahead → Chapter 06
We now know how much capacity costs. Next we exploit it: kernel methods lift data into rich feature spaces where linear separation is easy, while the margin — not the parameter count — keeps effective capacity under control.