PAC Learning Explained With a Simple Example
Learn what probably approximately correct means by learning a threshold, deriving the sample size, and checking it by simulation.
Key takeaways
- PAC learning sets an error tolerance ε and a failure probability δ, then asks how many examples satisfy both.
- The guarantee holds for every data distribution, provided training and future examples are drawn independently from the same one.
- For a threshold on a line with noise-free labels, about (1/ε)·ln(1/δ) examples are enough.
- Tightening ε costs far more data than tightening δ, because δ appears only inside a logarithm.
- The bounds are worst-case promises, so real problems often need fewer examples than they suggest.
A learning method is PAC (probably approximately correct) if, given enough random examples, it returns a model that with high probability has low error. "Approximately" refers to the error, at most ε. "Probably" refers to the chance of success, at least 1 − δ over the random draw of training data.
The framework, introduced by Leslie Valiant in 1984, asks a precise question: how many examples guarantee both? The easiest way to see the answer is to learn a single threshold.
The threshold problem
Say each input x is a number, such as a sensor reading, and the label is 1 when x ≥ t* and 0 otherwise. The true threshold t* is unknown. Inputs are drawn from some distribution D that you also do not know.
You get n labeled examples. Your learner uses this rule:
- Look at all examples labeled 1.
- Set t̂ to the smallest x among them.
- If there are none, predict 0 everywhere.
Every positive example sits at or above t*, so t̂ ≥ t*. The learned rule can only err on inputs that fall between t* and t̂: truly positive, predicted negative. Its error is the probability that a new input from D lands in that gap.
Deriving the number of examples
When could the error exceed ε? Mark off a strip that starts at t* and extends upward just far enough to hold probability ε under D. If even one training point lands in that strip, it is positive, so t̂ falls inside the strip and the error is at most ε.
The learner can fail only if all n points miss the strip. (If there is less than ε probability above t* altogether, the error can never exceed ε.) Each point misses with probability at most 1 − ε, and the points are independent.
P(error > ε) ≤ (1 − ε)ⁿ all n points miss the strip
≤ e^(−εn) because 1 − ε ≤ e^(−ε)
e^(−εn) ≤ δ when n ≥ (1/ε) ln(1/δ) Take ε = 0.05 and δ = 0.01. Then ln(100) ≈ 4.605, and 4.605/0.05 ≈ 92.1, so 93 examples are enough. Using (1 − ε)ⁿ ≤ δ directly gives n ≥ 89.8, so 90 already suffice. The exponential step costs a few examples and buys a cleaner formula.
Notice what you did not need to know: the location of t*, or the shape of D. The points could be uniform, bell-shaped or lumpy. The guarantee covers them all because error is measured under the same D that produced the data.
Check it by simulation
With inputs uniform on [0, 1] and t* = 0.3, the error is simply t̂ − 0.3. The code runs the whole experiment many times.
import numpy as np
rng = np.random.default_rng(0)
t_true, n, eps, trials = 0.3, 90, 0.05, 20000
x = rng.uniform(size=(trials, n)) # one experiment per row
positive = np.where(x >= t_true, x, 1.0) # 1.0 if no positives
t_hat = positive.min(axis=1) # shape (trials,)
error = t_hat - t_true
print(np.mean(error > eps)) The theoretical failure rate in this setting is 0.95⁹⁰ ≈ 0.0099, and your printed fraction should be close to it. Now reduce n to 30 and the failure rate rises to about 0.95³⁰ ≈ 0.21.
What accuracy and confidence cost
The formula n ≥ (1/ε)·ln(1/δ) is easy to tabulate. Each entry is rounded up.
| Error limit ε | δ = 0.05 | δ = 0.01 | δ = 0.001 |
|---|---|---|---|
| 0.10 | 30 | 47 | 70 |
| 0.05 | 60 | 93 | 139 |
| 0.01 | 300 | 461 | 691 |
Read down a column: making the error limit ten times stricter multiplies the data by ten. Read across a row: cutting the failure probability from 0.05 to 0.001, a fiftyfold change, only multiplies it by about 2.3.
This lopsidedness is typical of learning guarantees. Confidence is cheap and precision is expensive. When someone asks for a tighter model, expect the data requirement to be the thing that moves.
A second example: learning a rectangle
Now let inputs be points in the plane, and let positives be exactly those inside an unknown axis-aligned rectangle. A natural learner draws the smallest rectangle that contains all positive training points. It sits inside the true one, so errors again occur only in the leftover region.
That region is covered by four strips, one along each side of the true rectangle. Choose each strip to hold probability ε/4. If every strip catches at least one training point, the learned rectangle reaches into all four, and the total error is at most ε.
P(a given strip is missed) ≤ (1 − ε/4)ⁿ ≤ e^(−εn/4)
P(any of the four is missed) ≤ 4·e^(−εn/4) union bound
4·e^(−εn/4) ≤ δ when n ≥ (4/ε) ln(4/δ) With ε = 0.05 and δ = 0.01, this gives 80 × ln(400) ≈ 479.3, so 480 examples suffice. A richer family of rules, with four unknown edges instead of one threshold, asks for more data.
The general definition
A concept is the true labeling rule, and a concept class is the set of rules it might be: here, all thresholds. A class is PAC learnable if there is an algorithm such that, for every ε and δ between 0 and 1, every distribution D and every concept in the class, the following holds. Given a number of independent examples that grows polynomially in 1/ε and 1/δ (and in a measure of problem size), the algorithm returns, with probability at least 1 − δ, a hypothesis with error at most ε.
Valiant's original formulation also asks that the algorithm run in polynomial time. That requirement matters. Some classes can be learned from a modest number of examples, yet no efficient algorithm is known, or one is ruled out under standard complexity or cryptographic assumptions.
| Symbol | Name | What shrinking it means |
|---|---|---|
| ε | Accuracy parameter | Demanding a more accurate model |
| δ | Confidence parameter | Demanding that success be more likely |
| n | Sample size | Fewer examples to work with |
| D | Data distribution | Unknown, but the same at training and test time |
From one threshold to many rules
The same argument works for any finite set H of candidate rules, as long as one of them is perfectly correct. This is the realizable case. Learner: return any rule in H that makes no training mistakes.
A particular bad rule, with error above ε, survives n examples with probability at most (1 − ε)ⁿ. There are at most |H| bad rules. The union bound says the chance that any of them survives is at most the sum of their chances, so it is at most |H|·e^(−εn). Setting that below δ gives:
n ≥ (1/ε) ( ln|H| + ln(1/δ) ) The number of candidates enters through a logarithm. Going from a thousand rules to a million adds only ln(1000) ≈ 6.9 to the sum in parentheses.
Our thresholds form an infinite class, so this formula does not apply to them. We used the geometry of the line instead. The general tool for infinite classes is the VC dimension.
When no rule is perfect
Real labels are noisy and the model class rarely contains the truth. Agnostic PAC learning drops the realizable assumption and changes the goal: find a rule whose error is within ε of the best rule in H.
The price is steeper. Estimating error rates that are not zero requires on the order of 1/ε² examples instead of 1/ε. For ε = 0.01 that is a factor of about a hundred between 1/ε and 1/ε². Sample complexity works through the formulas and numbers.
What the framework leaves out
PAC theory is clear about its assumptions, and you should be too.
- Examples must be independent and from the distribution you will face. Drift breaks the promise, as discussed in the i.i.d. assumption.
- Bounds hold for the worst distribution and concept. Your problem may be much friendlier.
- It says nothing about whether the class contains a rule good enough to be useful.
- For large neural networks, classical worst-case bounds are often far larger than 1 for an error rate, which makes them uninformative. Explaining their generalization remains an active research area.
The value lies in the habit of thought: state what accuracy you want, how sure you need to be, what you assume, and then ask what the data can support.
Common questions
Is δ the same as the error rate?
No. ε limits how often the final model is wrong on new inputs. δ limits how often the whole training process, rerun on a fresh sample, produces a model that misses that ε target.
Does a 95% confidence guarantee mean my particular model is probably fine?
The probability refers to the random training sample before you see it. Once you have a specific model, you can test it on fresh data and get a much tighter statement about that model.
Why is the learner's tie-breaking rule important?
In the threshold problem, any t̂ above the largest negative example and at or below the smallest positive one fits the training data. Choosing the smallest positive is convenient for the proof, since errors fall on one side only. Another consistent choice, such as the midpoint of the gap, also works well in practice, though the argument then has to cover errors on either side of t*. The finite-class result is stronger in this respect: it covers every rule with zero training mistakes.
What if I have more examples than the bound requires?
The guarantee still holds, and you can solve for a smaller ε: with n examples in the threshold problem, ε = ln(1/δ)/n. With 1,000 examples and δ = 0.01, that is about 0.0046.