Post navigation

Occam’s Razor and PAC-learning

So far our discussion of learning theory has been seeing the definition of PAC-learning, tinkering with it, and seeing simple examples of learnable concept classes. We’ve said that our real interest is in proving big theorems about what big classes of problems can and can’t be learned. One major tool for doing this with PAC is the concept of VC-dimension, but to set the stage we’re going to prove a simpler theorem that gives a nice picture of PAC-learning when your hypothesis class is small. In short, the theorem we’ll prove says that if you have a finite set of hypotheses to work with, and you can always find a hypothesis that’s consistent with the data you’ve seen, then you can learn efficiently. It’s obvious, but we want to quantify exactly how much data you need to ensure low error. This will also give us some concrete mathematical justification for philosophical claims about simplicity, and the theorems won’t change much when we generalize to VC-dimension in a future post.

The Chernoff bound

One tool we will need in this post, which shows up all across learning theory, is the Chernoff-Hoeffding bound. We covered this famous inequality in detail previously on this blog, but the part of that post we need is the following theorem that says, informally, that if you average a bunch of bounded random variables, then the probability this average random variable deviates from its expectation is exponentially small in the amount of deviation. Here’s the slightly simplified version we’ll use:

Theorem: Let be independent random variables whose values are in the range . Call , , and . Then for all ,

One nice thing about the Chernoff bound is that it doesn’t matter how the variables are distributed. This is important because in PAC we need guarantees that hold for any distribution generating data. Indeed, in our case the random variables above will be individual examples drawn from the distribution generating the data. We’ll be estimating the probability that our hypothesis has error deviating more than , and we’ll want to bound this by , as in the definition of PAC-learning. Since the amount of deviation (error) and the number of samples () both occur in the exponent, the trick is in balancing the two values to get what we want.

Realizability and finite hypothesis classes

Let’s recall the PAC model once more. We have a distribution generating labeled examples , where is an unknown function coming from some concept class . Our algorithm can draw a polynomial number of these examples, and it must produce a hypothesis from some hypothesis class (which may or may not contain ). The guarantee we need is that, for any , the algorithm produces a hypothesis whose error on is at most , and this event happens with probability at least . All of these probabilities are taken over the randomness in the algorithm’s choices and the distribution , and it has to work no matter what the distribution is.

Let’s introduce some simplifications. First, we’ll assume that the hypothesis and concept classes and are finite. Second, we’ll assume that , so that you can actually hope to find a hypothesis of zero error. This is called realizability. Later we’ll relax these first two assumptions, but they make the analysis a bit cleaner. Finally, we’ll assume that we have an algorithm which, when given labeled examples, can find in polynomial time a hypothesis that is consistent with every example.

These assumptions give a trivial learning algorithm: draw a bunch of examples and output any consistent hypothesis. The question is, how many examples do we need to guarantee that the hypothesis we find has the prescribed generalization error? It will certainly grow with , but we need to ensure it will only grow polynomially fast in this parameter. Indeed, realizability is such a strong assumption that we can prove a polynomial bound using even more basic probability theory than the Chernoff bound.

Theorem: A algorithm that efficiently finds a consistent hypothesis will PAC-learn any finite concept class provided it has at least samples, where

Proof. All we need to do is bound the probability that a bad hypothesis (one with error more than ) is consistent with the given data. Now fix , and draw examples and let be any hypothesis that is consistent with the drawn examples. Suppose that the bad thing happens, that .

Because the examples are all drawn independently from , the chance that all examples are consistent with is

What we’re saying here is, the probability that a specific bad hypothesis is actually consistent with your drawn examples is exponentially small in the error tolerance. So if we apply the union bound, the probability that some hypothesis you could produce is bad is at most , where is the number of hypotheses the algorithm might produce.

A crude upper bound on the number of hypotheses you could produce is just the total number of hypotheses, . Even cruder, let’s use the inequality to give the bound

Now we want to make sure that this probability, the probability of choosing a high-error (yet consistent) hypothesis, is at most . So we can set the above quantity less than and solve for :

Taking logs and solving for gives the desired bound.

An obvious objection is: what if you aren’t working with a hypothesis class where you can guarantee that you’ll find a consistent hypothesis? Well, in that case we’ll need to inspect the definition of PAC again and reevaluate our measures of error. It turns out we’ll get a similar theorem as above, but with the stipulation that we’re only achieving error within epsilon of the error of the best available hypothesis.

But before we go on, this theorem has some deep philosophical interpretations. In particular, suppose that, before drawing your data, you could choose to work with one of two finite hypothesis classes , with . If you can find a consistent hypothesis no matter which hypothesis class you use, then this theorem says that your generalization guarantees are much stronger if you start with the smaller hypothesis class.

In other words, all else being equal, the smaller set of hypotheses is better. For this reason, the theorem is sometimes called the “Occam’s Razor” theorem. We’ll see a generalization of this theorem in the next section.

Unrealizability and an extra epsilon

Now suppose that $H$ doesn’t contain any hypotheses with error less than . What can we hope to do in this case? One thing is that we can hope to find a hypothesis whose error is within of the minimal error of any hypothesis in . Moreover, we might not have any consistent hypotheses for some data samples! So rather than require an algorithm to produce an that is perfectly consistent with the data, we just need it to produce a hypothesis that has minimal empirical error, in the sense that it is as close to consistent as the best hypothesis of on the data you happened to draw. It seems like such a strategy would find you a hypothesis that’s close to the best one in , but we need to prove it and determine how many samples we need to draw to succeed.

So let’s make some definitions to codify this. For a given hypothesis, call the true error of on the distribution . Our assumption is that there may be no hypotheses in with . Next we’ll call the empirical error .

Definition: We say a concept class is agnostically learnable using the hypothesis class if for all and all distributions (and all ), there is a learning algorithm which produces a hypothesis that with probability at least satisfies

and everything runs in the same sort of polynomial time as for vanilla PAC-learning. This is called the agnostic setting or the unrealizable setting, in the sense that we may not be able to find a hypothesis with perfect empirical error.

We seek to prove that all concept classes are agnostically learnable with a finite hypothesis class, provided you have an algorithm that can minimize empirical error. But actually we’ll prove something stronger.

Theorem: Let be a finite hypothesis class and the number of samples drawn. Then for any , with probability the following holds:

In other words, we can precisely quantify how the empirical error converges to the true error as the number of samples grows. But this holds for all hypotheses in , so this provides a uniform bound of the difference between true and empirical error for the entire hypothesis class.

Proving this requires the Chernoff bound. Fix a single hypothesis . If you draw an example , call the random variable which is 1 when , and 0 otherwise. So if you draw samples and call the -th variable , the empirical error of the hypothesis is . Moreover, the actual error is the expectation of this random variable since .

So what we’re asking is the probability that the empirical error deviates from the true error by a lot. Let’s call “a lot” some parameter (the reason for dividing by two will become clear in the corollary to the theorem). Then plugging things into the Chernoff-Hoeffding bound gives a bound on the probability of the “bad event,” that the empirical error deviates too much.

Now to get a bound on the probability that some hypothesis is bad, we apply the union bound and use the fact that is finite to get

Now say we want to bound this probability by . We set , solve for , and get

This gives us a concrete quantification of the tradeoff between and . Indeed, if we pick to be this large, then solving for gives the exact inequality from the theorem.

Now we know that if we pick enough samples (polynomially many in all the parameters), and our algorithm can find a hypothesis of minimal empirical error, then we get the following corollary:

Corollary: For any , the algorithm that draws examples and finds any hypothesis of minimal empirical error will, with probability at least , produce a hypothesis that is within of the best hypothesis in .

Proof. By the previous theorem, with the desired probability, for all we have . Call . Then because the empirical error of is also minimal, we have . And using the previous theorem again and the triangle inequality, we get . In words, the true error of the algorithm’s hypothesis is close to the error of the best hypothesis, as desired.

Next time

Both of these theorems tell us something about the generalization guarantees for learning with hypothesis classes of a certain size. But this isn’t exactly the most reasonable measure of the “complexity” of a family of hypotheses. For example, one could have a hypothesis class with a billion intervals on (say you’re trying to learn intervals, or thresholds, or something easy), and the guarantees we proved in this post are nowhere near optimal.

So the question is: say you have a potentially infinite class of hypotheses, but the hypotheses are all “simple” in some way. First, what is the right notion of simplicity? And second, how can you get guarantees based on that analogous to these? We’ll discuss this next time when we define the VC-dimension.

Write code, not cover letters
Triplebyte's common application lets talented programmers skip resume and recruiter screens while applying to multiple top tech companies at once. Beat their online coding quiz to get started. People interested in math and physics tend to do well.