VC Dimension and PAC Learning
Shattering, VC dimension, sample complexity bounds, and the theory behind how much data is enough.
Assumes you know
VC Dimension and PAC Learning
Intuition first
Everyone knows more data helps and simpler models generalise better. This lesson makes both statements quantitative: given a model family and a tolerance, how many examples do you actually need?
The key move is finding the right measure of model complexity. Parameter count will not do — a one-parameter model can be infinitely flexible, as we will see. What works is asking how many points the family can label in every possible way. A straight line in the plane can realise all labellings of three well-placed points, but not all 16 labellings of four. That number, three, is its VC dimension, and it turns out to be exactly what controls the sample size you need.
The resulting bounds are far too loose for practical use. Their value is structural: they tell you what the generalisation gap depends on, and what it does not.
| Symbol | Meaning | Read aloud |
|---|---|---|
| ℋ | Hypothesis class | script H |
| VC(ℋ) | Vapnik–Chervonenkis dimension of ℋ | V C of H |
| R(h) | True risk of hypothesis h | risk of h |
| R̂(h) | Empirical risk on n samples | R hat of h |
| ε | Accuracy tolerance — how close to optimal | epsilon |
| δ | Failure probability — confidence is 1 − δ | delta |
Shattering and VC dimension
A hypothesis class shatters a set of points if, for every one of the possible label assignments, some realises it.
Note "some set", not "every set" — one shatterable configuration suffices.
Standard values:
| Hypothesis class | VC dimension |
|---|---|
| Thresholds on , | 1 |
| Intervals on | 2 |
| Linear separators in | |
| Axis-aligned rectangles in | 4 |
| Sine classifiers | |
| Neural network with weights (ReLU) | |
| 1-nearest-neighbour |
The PAC framework
Probably Approximately Correct: we cannot demand a perfect model with certainty, so we demand a nearly-correct one with high probability.
A class is PAC-learnable if there is an algorithm that, for any and enough samples, returns with
Two knobs: is how much error you tolerate, is how often you accept failure.
The generalisation bound
With probability at least , simultaneously for all :
Ignoring logarithms, the gap scales as
Sample complexity
Inverting the bound gives the number of examples needed:
Solved problem 1 · How much data does a linear classifier need?
You want a linear classifier in with generalisation gap at most and confidence . Estimate the sample complexity, then compare with .
Step 1 — VC dimension
Linear separators in have
Step 2 — apply the sample complexity form
Using the standard constant-free version :
Step 3 — tighten the tolerance to 0.01
Step 4 — note the two scalings separately
Reducing from to — a factor of 5 — multiplied the requirement by . The dependence is brutal, and it is why the last few points of accuracy are so much more expensive than the first.
Now vary the confidence instead. Tightening from to :
A 50-fold reduction in failure probability costs only 16% more data, because enters logarithmically. High confidence is cheap; high accuracy is expensive.
Step 5 — reality check
In practice a 20-feature logistic regression performs well with a few thousand examples, not 9,600 — and far better than the bound's worst case. The bound is distribution-free: it must hold for the most adversarial data distribution imaginable, so it is loose by a wide margin on real data.
Answer
About 9,600 examples for and about 240,000 for . The scaling dominates everything; the term is nearly free. Treat these as upper bounds on the worst case, not as forecasts.
Why the bounds are loose, and what replaced them
VC bounds are distribution-free — they hold for any data distribution, including maliciously constructed ones. That generality is exactly what makes them loose on benign real data.
They also fail spectaculary on modern networks. A network with parameters has an astronomically large VC dimension, so the bound is vacuous — it permits a generalisation gap above 1. Yet such models generalise. Worse, deep networks can perfectly fit randomly labelled data, which means their capacity genuinely is enormous, and yet they still generalise on real labels.
Refinements that do better:
- Margin bounds — depend on rather than dimension, which is why SVMs work in very high dimensions.
- Rademacher complexity — data-dependent, measuring how well the class fits random noise on your sample rather than in the worst case.
- PAC-Bayes — bounds in terms of the distance between a learned posterior over hypotheses and a prior; currently the most successful route for deep networks.
- Algorithmic stability — bounds based on how much the output changes when one training point is swapped. Applies to SGD directly.
What to actually take away
The bounds are not calculators. They are a correct account of what the generalisation gap depends on:
- Quadruple the data to halve the gap. This sets realistic expectations for data-collection projects.
- Confidence is cheap, accuracy is not. versus .
- What matters is complexity relative to sample size, not complexity alone.
- Regularisation works by reducing effective complexity — a claim the theory makes precise.
Exercise 1
Show that the VC dimension of axis-aligned rectangles in is exactly 4.
Show solutionHide solution
Two parts: exhibit 4 shattered points, and show 5 can never be.
At least 4. Place four points in a diamond: top , bottom , left , right . For any subset of these four, take the smallest axis-aligned rectangle containing exactly the points of . Because each point is the unique extreme point in one of the four directions, the bounding box of contains no point outside — removing the topmost point, for instance, lowers the top edge below it. All subsets are realisable, so these four are shattered.
Not 5. Take any five points. Identify the point with the largest , smallest , largest , and smallest — at most four points are selected this way, so at least one point is not extreme in any direction. Then lies inside the bounding box of the other four.
Consider the labelling that marks the other four positive and negative. Any rectangle containing all four positives must contain their bounding box, which contains — so is included and labelled positive. That labelling is unachievable, so no set of 5 points is shattered.
Hence .
Sanity check against the general pattern: an axis-aligned rectangle in is specified by numbers and has VC dimension , giving 4 for . ✓
Exercise 2
A model class has VC dimension 500. You have 1,000 training examples and zero training error. Should you trust the model?
Show solutionHide solution
No. The ratio is far too high.
Plugging into the asymptotic form, the generalisation gap is on the order of
A bound permitting a gap of 0.71 is vacuous for a classifier whose error is between 0 and 1 — it tells you the true error could be anywhere.
The intuition behind the formalism: a class with VC dimension 500 can shatter 500 points, meaning it can produce any labelling of 500 points. With only 1,000 examples, achieving zero training error is weak evidence of learning, because the class is flexible enough to fit a large fraction of arbitrary label patterns. Zero training error is close to guaranteed whether or not signal exists.
What to do:
- Hold out a test set and measure. The theory is loose; the empirical gap is what matters.
- Reduce effective complexity — regularise, constrain, or use a simpler class. Aim for .
- Run the randomisation check. Shuffle the labels and refit. If training error is still near zero, the model is memorising, and the zero error on real labels means nothing.
- Get more data. For a meaningful bound you would want in the tens of thousands at .
That completes Machine Learning Foundations. Next module: Supervised Learning, where these principles are applied to specific algorithms, starting with Simple Linear Regression.