Skip to content

Feasibility of Learning: Hoeffding's Inequality and Guarantees Outside the Data | NTU Hsuan-Tien Lin Machine Learning Foundations Lecture 4

Sep 30, 20261 min
TL;DRThis lecture first shows that the data D alone cannot determine the answer outside D (No Free Lunch), then adds one assumption: the data and the future inputs are drawn independently from the same distribution. Hoeffding's inequality then guarantees that, for a hypothesis h fixed in advance, the probability that E_in and E_out differ by more than ε is at most 2exp(−2ε²N). An algorithm has to choose among M hypotheses, so the bound is multiplied by M and becomes 2M exp(−2ε²N); with finitely many hypotheses, enough data, and a small E_in, learning is feasible.

Look up & save

Loading dictionary…

🌏 中文版

Video status: Videos included. This article is written from the official MOOC handout 04_handout.pdf and transcripts of this lecture's four official videos, with formulas following the handout. The transcripts are machine transcripts made for this article (Whisper), not official captions, and no human has proofread them. The videos are taught in Mandarin; the slides are in English. Each section opens with its official video and the approximate time ranges. Page numbers refer to the number at the lower right of each slide (0/26 to 26/26), and wherever the text says "in the lecture" it is paraphrasing what is said in the video.

This is Foundations Lecture 4 in Reading NTU Hsuan-Tien Lin Machine Learning Foundations & Techniques. The Roadmap on page 1 of the handout divides Foundations into four questions, and this is the last lecture under the first one, When Can Machines Learn? The previous lecture, Foundations Lecture 3: Types of Learning, is left with a single line on the Roadmap: from here on the focus is binary classification or regression from a batch of supervised data with concrete features. Reviewing it in the lecture, Lin says the previous lecture ended on a teaser: even in a setting this central, learning may turn out to be impossible.

This lecture starts from that bad news. The PLA of Foundations Lecture 2 can get every example it has seen right, but the bank cares about customers who have not walked in yet. If everything seen is right, does that guarantee the unseen will be mostly right too? The four sections answer in order: not without an assumption; once we add "the data come from independent sampling", one hypothesis fixed in advance can be verified; and when the algorithm has to choose among many hypotheses, the guarantee survives, but at a price.

The prerequisites are the learning flow diagram of Foundations Lecture 1 (ff, D\mathcal{D}, H\mathcal{H}, A\mathcal{A}, gg), the PLA of Foundations Lecture 2, and basic probability (independent events, the binomial distribution, the exponential function and the natural logarithm). After reading, you should be able to write out on your own the few lines that lead from Hoeffding's inequality for one hypothesis to the union bound for MM hypotheses, plug in numbers to compute the bound, and say clearly how "verification" differs from "learning".

Why the data alone cannot guarantee the answer outside the data

YouTube:Feasibility of Learning :: Learning is Impossible? @ Machine Learning Foundations (機器學習基石)

(Video 00:18–01:37 reviews the previous lecture, 01:37–05:28 is the picture puzzle, 05:28–11:45 is the three-bit example and No Free Lunch, and Fun Time follows.)

A puzzle where every answer can be called wrong

Page 2 of the handout poses a learning puzzle for humans; in the lecture, Lin jokes that it tests human intelligence rather than artificial intelligence. There are six 3×3 black-and-white grid pictures: the three in the top row are labeled yn=−1y_n = -1, the three in the bottom row yn=+1y_n = +1, and the question is what g(x)g(\mathbf{x}) is for a seventh picture. Written as text, with ■ for a black cell, □ for a white cell, and the three rows from top to bottom separated by " / ":

PictureLabelThree rows (top to bottom)Black cells
Top left−1-1■□□ / ■□■ / □■□4
Top middle−1-1■□□ / □□■ / ■□■4
Top right−1-1■□□ / □□■ / □□□2
Bottom left+1+1□□■ / □■□ / ■□□3
Bottom middle+1+1□■□ / ■□■ / □■□4
Bottom right+1+1□■■ / ■■□ / □■■6
Picture to predict?■□□ / □■□ / □□■3

Page 3 is titled Two Controversial Answers and lists four rules, each of which classifies all six pictures correctly:

RuleOn the six picturesOn the seventh picture
symmetry ⇔ +1+1Each of the three bottom pictures has an axis of symmetry; none of the three top ones doesSymmetric about the diagonal, +1+1
(black or white count = 3) or (black count = 4 and middle-top black) ⇔ +1+1Bottom row: 3 black; 4 black with middle-top black; 3 white. None of the top row qualifies3 black cells, +1+1
left-top black ⇔ −1-1The left-top cell is black in every top picture and white in every bottom pictureLeft-top is black, −1-1
middle column contains at most 1 black and right-top white ⇔ −1-1All three top pictures qualify; none of the three bottom ones does1 black in the middle column and right-top white, −1-1

For this article, the seven pictures were entered as in the table above and each rule was checked in Python: all four rules are correct on all six labeled pictures, the first two say +1+1 for the seventh picture, and the last two say −1-1.

In the lecture this becomes a dialogue. If the student answers −1-1, the teacher says the rule in mind was symmetry and the answer is +1+1; if the student answers +1+1, the teacher says the rule in mind was the left-top cell and the answer is −1-1. The handout concludes: all valid reasons, and your adversarial teacher can always call you "didn't learn". Lin adds in the lecture that this puzzle already uses the most central setting, binary classification with supervised labels and six examples, and still any answer can be ruled wrong.

A version small enough to enumerate

The picture puzzle allows too many rules to count. Page 4 shrinks the problem until everything can be listed: the input is three bits, X={0,1}3\mathcal{X} = \{0,1\}^3, 8 possible inputs in all; the output is Y={∘,×}\mathcal{Y} = \{\circ, \times\}. The data D\mathcal{D} give the answers for 5 of those inputs:

xn\mathbf{x}_nyn=f(xn)y_n = f(\mathbf{x}_n)
000○
001×
010×
011○
100×

With 8 inputs and 2 possible outputs for each, there are 28=2562^8 = 256 functions from X\mathcal{X} to Y\mathcal{Y}. The handout says we can then enumerate all candidate ff as H\mathcal{H}; in the lecture, Lin explains that since there are only 256 of them, we simply put them all into the hypothesis set. The algorithm picks from it a gg that is correct on all 5 examples, that is, all g(xn)=yng(\mathbf{x}_n) = y_n. The handout notes "like PLA" here, and Lin explains in the lecture that PLA does roughly the same thing: it finds a line that completely separates the circles and crosses it has seen. The question is whether such a gg resembles ff.

Page 5 lays the answer out as a table. The inputs D\mathcal{D} does not cover are 101, 110, and 111; the true answer on each can be ○ or ×, so there are 23=82^3 = 8 target functions fully consistent with D\mathcal{D}, which the handout calls f1f_1 through f8f_8:

x\mathbf{x}yyggf1f_1f2f_2f3f_3f4f_4f5f_5f6f_6f7f_7f8f_8
000○○○○○○○○○○
001××××××××××
010××××××××××
011○○○○○○○○○○
100××××××××××
101?○○○○××××
110?○○××○○××
111?○×○×○×○×

The first five rows are D\mathcal{D}: the eight ff look identical there, and the algorithm has tuned gg to match. The handout's two-line conclusion:

  • g≈fg \approx f inside D\mathcal{D}: sure!
  • g≈fg \approx f outside D\mathcal{D}: No! (but that's really what we want!)

In the lecture, Lin walks through the last three rows with a concrete gg: suppose your gg predicts ○×○ on 101, 110, and 111. In the worst case the true ff happens to be ×○× (f6f_6 in the table), and all three are wrong.

As an addition in this article, count this gg against each of the eight ff. The number of the three new inputs it gets right, for f1f_1 through f8f_8 in order, is 2, 1, 3, 2, 1, 0, 2, 1, a total of 12 and an average of 12/8=1.512/8 = 1.5, exactly half. Any other gg does the same: listing all 8 possible predictions in Python for this article, each one scores one 3, three 2s, three 1s, and one 0 against the eight ff. Three new inputs with a one-half chance on each is no different from flipping coins. This is what Lin means in the lecture: if all eight ff are possible, then on average we seem to have learned nothing.

What No Free Lunch says

The last sentence on page 5 of the handout: learning from D\mathcal{D} (to infer something outside D\mathcal{D}) is doomed if any "unknown" ff can happen. In the lecture, Lin says a line of research in machine learning calls this No Free Lunch.

The condition in that sentence deserves a careful read. As Lin puts it in the lecture, we have insisted all along that ff is unknown; if we insist on only that and assume nothing else, we cannot say whether gg is good or bad outside the data, and to say anything we have to add some assumptions. Lin also reminds us that the part outside the data really is what we want: in the credit card example, the bank wants to know whether gg gives the same answer as the ideal formula when a new customer walks in, and getting old customers right does not count.

So the question this section leaves behind is which assumption to add. The one added in the next three sections has nothing to do with what ff looks like; it only concerns where the data come from.

Fun Time: a brain teaser with a single example

Question (page 6): This is a popular "brain-storming" problem, with a claim that 2% of the world's cleverest population can crack its "hidden pattern":

(5,3,2)→151022,(7,2,5)→ ?(5, 3, 2) \rightarrow 151022, \qquad (7, 2, 5) \rightarrow \ ?

It is like a "learning problem" with N=1N = 1, x1=(5,3,2)\mathbf{x}_1 = (5, 3, 2), y1=151022y_1 = 151022. Learn a hypothesis from the one example to predict on x=(7,2,5)\mathbf{x} = (7, 2, 5). What is your answer?

  1. 151026
  2. 143547
  3. I need more examples to get the correct answer
  4. there is no "correct" answer

Answer: 4. The handout's reason is that this is of the same nature as the No Free Lunch problems just discussed: we cannot hope to be correct under this adversarial setting. It adds in passing that option 2 is the designer's answer: the first two digits are x1⋅x2x_1 \cdot x_2, the next two digits are x1⋅x3x_1 \cdot x_3, and the last two digits are x1⋅x2+x1⋅x3−x2x_1 \cdot x_2 + x_1 \cdot x_3 - x_2. Checking: (5,3,2)(5,3,2) gives 15, 10, and 15+10−3=2215 + 10 - 3 = 22, which concatenate to 151022; (7,2,5)(7,2,5) gives 14, 35, and 14+35−2=4714 + 35 - 2 = 47, which concatenate to 143547.

Option 1 can be justified too. Here is a rule made up for this article, not from the slides: y=151012+2x1y = 151012 + 2x_1. (5,3,2)(5,3,2) gives 151012+10=151022151012 + 10 = 151022, matching the data; (7,2,5)(7,2,5) gives 151012+14=151026151012 + 14 = 151026. With a single example both rules are fully correct, and nothing says which one is the real one.

Option 3 sounds cautious but is also wrong. The table above already demonstrated it: after seeing 5 of the 8 inputs, anything can still happen on the remaining 3. However many examples there are, as long as the question is about an unseen input and nothing is assumed about ff, there is no such thing as the correct answer. In the lecture, Lin explains that whatever number you answer, you can claim to be right; the answer circulating online is just one interpretation.

A problem where inference works: from a handful of marbles to the whole bin

YouTube:Feasibility of Learning :: Probability to the Rescue @ Machine Learning Foundations (機器學習基石)

(Video 00:01–01:27 poses the bin problem, 01:27–04:33 is sampling, 04:33–08:19 is Hoeffding's inequality and PAC, 08:19–10:29 reads the formula, and Fun Time follows.)

The bin and the sample

Page 7 of the handout takes a step back: inferring the unknown target ff outside D\mathcal{D} is difficult in learning, so can we infer something unknown in other scenarios? The example is a bin of many, many orange and green marbles. What is the orange portion? We do not know. In the lecture, Lin says there are too many marbles to count one by one.

Page 8 does what the first class of a statistics course does: grab a handful and look.

BinSample
Orangeprobability μ\mufraction ν\nu
Greenprobability 1−μ1 - \mufraction 1−ν1 - \nu
Known or notμ\mu unknownν\nu known

The sample is NN marbles sampled independently. The numbers Lin uses in the lecture are 10 marbles with 3 of them orange, so you guess that about 30% of the bin is orange. On this page the handout introduces two words that stay in use from here on: ν\nu is the in-sample quantity and μ\mu the out-of-sample quantity. The question is whether ν\nu says anything about μ\mu.

Page 9 answers in two halves, under the title Possible versus Probable:

  • No, possibly not: the sample can be mostly green while the bin is mostly orange.
  • Yes, probably yes: in-sample ν\nu is likely close to the unknown μ\mu.

"Can possibly happen" and "will probably happen" are two different things. In the lecture, Lin says a bin that is mostly orange yielding a handful that is almost all green has a very small probability but does happen, so we cannot get a certain answer and can only say it is so with high probability. As an addition in this article, here is the difference from before: in the No Free Lunch section the adversary could name the worst ff; here nobody names which handful you get, the sampling is random, and the worst case is just an event with small probability.

Hoeffding's inequality

The mathematical form of "probably close" is on page 10. In a big sample (NN large), ν\nu is probably within ϵ\epsilon of μ\mu:

P[ ∣ν−μ∣>ϵ ] ≤ 2exp⁡(−2ϵ2N)\mathbb{P}\big[\,\lvert \nu - \mu \rvert > \epsilon\,\big] \ \le\ 2\exp\big(-2\epsilon^2 N\big)

This is called Hoeffding's Inequality. The handout notes that it applies to marbles, coins, polling, and so on; Lin's examples in the lecture are that the fraction of heads over many coin flips approaches the coin's true probability of heads, and that a telephone poll before an election comes out close to the final vote share. The handout does not prove the inequality; this article does not either, and instead uses numbers to confirm what it says.

Each symbol in the formula:

  • The left side is the probability of a "bad event": the sample fraction ν\nu differs from the true probability μ\mu by more than ϵ\epsilon.
  • ϵ\epsilon is the error you are willing to tolerate.
  • The right side is an upper bound on that probability, with NN in the exponent and a minus sign in front. Doubling NN squares the exponential term (e−2a=(e−a)2e^{-2a} = (e^{-a})^2), so the bound falls fast.

As an addition in this article, one point that is easy to misread: the random quantity is ν\nu. μ\mu is a property of the bin, a fixed but unknown number; every handful may give a different ν\nu. The probability P\mathbb{P} measures what share of all possible outcomes of the act of grabbing a handful are bad ones.

The handout puts the conclusion in one sentence: the statement "ν=μ\nu = \mu" is probably approximately correct (PAC). In the lecture, Lin explains the two adverbs separately: probably means there is a high probability of being right; approximately means that when you draw 30% orange, the bin may hold 32%, 33%, 28%, or 29%, not exactly equal but close.

What makes this formula useful

Page 11 lists three points:

  1. Valid for all NN and ϵ\epsilon. NN does not have to pass some threshold before you can use it.
  2. The right side has no μ\mu. So there is no need to know μ\mu. Lin stresses in the lecture that this is why it can be used for inference: we never knew μ\mu in the first place, and the formula assumes nothing about μ\mu either.
  3. A larger NN, or a looser tolerance ϵ\epsilon, gives a higher probability for "ν≈μ\nu \approx \mu". Lin comments on the second half in the lecture: setting a larger tolerance of course makes the bad event less likely, but that is somewhat fooling yourself.

The conclusion at the bottom of the page: if NN is large, we can probably infer the unknown μ\mu by the known ν\nu.

The numbers below were computed for this article. First the bound itself, plugging NN and ϵ\epsilon into 2exp⁡(−2ϵ2N)2\exp(-2\epsilon^2 N):

NNϵ=0.3\epsilon = 0.3ϵ=0.1\epsilon = 0.1ϵ=0.05\epsilon = 0.05
100.3311.641.90
1003.0×10−83.0 \times 10^{-8}0.2711.21
1,000less than 10−7710^{-77}4.1×10−94.1 \times 10^{-9}0.0135
10,000smaller stillless than 10−8610^{-86}3.9×10−223.9 \times 10^{-22}

Two things are worth noticing. First, the table contains numbers above 1. A probability never exceeds 1, so "the bound is 1.64" says nothing at all. The formula being "valid" for all NN and ϵ\epsilon does not make it "useful" for all of them. The 10 marbles from the lecture are such a case: if you ask for an error within 0.1, Hoeffding gives no guarantee whatsoever; only when you relax to 0.3 does the bound drop to 0.331. Second, ϵ\epsilon appears squared. To halve the error requirement, NN has to become four times as large for the bound to stay the same; to cut it to one tenth, NN has to be a hundred times as large: N=100N = 100 with ϵ=0.1\epsilon = 0.1 and N=10,000N = 10{,}000 with ϵ=0.01\epsilon = 0.01 both give a bound of 0.271.

Next, is it really only an upper bound? Take μ=0.4\mu = 0.4 and ϵ=0.1\epsilon = 0.1 and compute the probability of the bad event exactly from the binomial distribution:

NNExact P[∣ν−μ∣>0.1]\mathbb{P}[\lvert\nu - \mu\rvert > 0.1]Hoeffding bound
100.3341.64
1000.03150.271
1,0008.7×10−118.7 \times 10^{-11}4.1×10−94.1 \times 10^{-9}

The exact values all sit below the bound, and by a wide margin. Computing the exact value needs μ=0.4\mu = 0.4 and computing the bound does not; that is the trade between the two: Hoeffding is loose, but you can compute it without knowing μ\mu.

Finally, use the formula in reverse. To have "the probability that the error exceeds ϵ\epsilon is at most δ\delta", require the right side 2exp⁡(−2ϵ2N)≤δ2\exp(-2\epsilon^2 N) \le \delta. Dividing both sides by 2 and taking the natural logarithm gives −2ϵ2N≤ln⁡(δ/2)-2\epsilon^2 N \le \ln(\delta/2), and multiplying through by −1-1 flips the inequality:

N ≥ 12ϵ2ln⁡2δN \ \ge\ \frac{1}{2\epsilon^2}\ln\frac{2}{\delta}

With ϵ=0.1\epsilon = 0.1 and δ=0.05\delta = 0.05 this gives N≥ln⁡40/0.02≈184.4N \ge \ln 40 / 0.02 \approx 184.4, so 185 marbles are enough. Tightening the error to ϵ=0.03\epsilon = 0.03 with the same δ\delta requires N≥ln⁡40/0.0018≈2049.4N \ge \ln 40 / 0.0018 \approx 2049.4, that is, 2,050 marbles. The handout does not write this reversed form in this lecture; it is the same inequality rearranged.

Fun Time: the bound for 10 marbles

Question (page 12): Let μ=0.4\mu = 0.4. Use Hoeffding's Inequality

P[ ∣ν−μ∣>ϵ ] ≤ 2exp⁡(−2ϵ2N)\mathbb{P}\big[\,\lvert \nu - \mu \rvert > \epsilon\,\big] \ \le\ 2\exp\big(-2\epsilon^2 N\big)

to bound the probability that a sample of 10 marbles will have ν≤0.1\nu \le 0.1. What bound do you get?

  1. 0.67
  2. 0.40
  3. 0.33
  4. 0.05

Answer: 3. The handout's solution is to set N=10N = 10 and ϵ=0.3\epsilon = 0.3: ν≤0.1\nu \le 0.1 means ν\nu is at least 0.3 below μ=0.4\mu = 0.4.

2exp⁡(−2×0.32×10)=2exp⁡(−1.8)≈2×0.1653=0.3312\exp\big(-2 \times 0.3^2 \times 10\big) = 2\exp(-1.8) \approx 2 \times 0.1653 = 0.331

The handout adds one remark: option 4 is the actual probability, and Hoeffding gives only an upper bound to that. This article checks the actual probability: ν≤0.1\nu \le 0.1 means at most 1 orange among the 10 marbles,

0.610+10×0.4×0.69≈0.0060+0.0403=0.04640.6^{10} + 10 \times 0.4 \times 0.6^{9} \approx 0.0060 + 0.0403 = 0.0464

which rounds to 0.05. The handout does not say where the other two options come from; what follows is this article's guess. Option 2, 0.40, is numerically just μ\mu itself and has nothing to do with the probability being asked for. Option 1, 0.67, numerically equals 1−0.3306=0.66941 - 0.3306 = 0.6694, that is, 1 minus the bound; that number is a lower bound on the probability that ν\nu and μ\mu differ by at most 0.3, whereas the question asks for an upper bound on the probability that ν≤0.1\nu \le 0.1, and the two point in opposite directions.

Two details of this question, as additions in this article. First, the event in the formula is a strict "greater than ϵ\epsilon", and at ν=0.1\nu = 0.1 the gap ∣ν−μ∣\lvert\nu - \mu\rvert is exactly 0.3. To be rigorous, take any ϵ′\epsilon' slightly smaller than 0.3; then ν≤0.1\nu \le 0.1 falls inside ∣ν−μ∣>ϵ′\lvert\nu - \mu\rvert > \epsilon' and the bound is 2exp⁡(−2ϵ′2×10)2\exp(-2\epsilon'^2 \times 10); as ϵ′\epsilon' approaches 0.3 the bound approaches 0.331, and the answer does not change. Second, Hoeffding covers both sides: ν\nu too low and ν\nu too high both count. The probability that ν≥0.7\nu \ge 0.7 is 0.0548, the two sides together come to 0.101, still below 0.331; the question asks only about the low side, so the actual value is smaller still.

Lin's comment on this question in the lecture: to compute the actual probability you must know μ\mu; Hoeffding holds for any μ\mu, so it overestimates and is only an upper limit.

Replace marbles with data: one fixed hypothesis can be verified

YouTube:Feasibility of Learning :: Connection to Learning @ Machine Learning Foundations (機器學習基石)

(Video 00:00–06:00 is the correspondence between the bin and learning, 06:00–07:27 is the components added to the flow diagram, 07:27–10:55 is E_in, E_out, and the guarantee, 10:55–15:00 discusses how verification differs from learning, and Fun Time follows.)

What the marbles in the bin are

In the lecture, Lin first asks the question on the students' behalf: this is a machine learning course, so why all the talk about marbles? Page 13 maps each component of the bin onto the learning problem:

BinLearning
unknown orange probability μ\muthe probability that a fixed hypothesis hh differs from the target ff
a marble in the binan x∈X\mathbf{x} \in \mathcal{X} in the input space
orangehh is wrong on this x\mathbf{x}: h(x)≠f(x)h(\mathbf{x}) \ne f(\mathbf{x})
greenhh is right on this x\mathbf{x}: h(x)=f(x)h(\mathbf{x}) = f(\mathbf{x})
a size-NN sample of i.i.d. marbles from the bincheck hh on D={(xn,yn)}\mathcal{D} = \{(\mathbf{x}_n, y_n)\} with i.i.d. xn\mathbf{x}_n, where yn=f(xn)y_n = f(\mathbf{x}_n)

In the lecture, Lin explains how this correspondence comes about. The unknown is ff, and estimating ff at every point of X\mathcal{X} is too hard, so ask an easier question first: given a hypothesis hh in hand and a new customer, does what hh says differ from what ff says? Then treat every x\mathbf{x} as a marble, painted orange where hh and ff disagree and green where they agree.

This painting has one precondition, which Lin states with emphasis in the lecture: you must have an hh in hand first, and it must be fixed; you cannot paint with this hh now and switch to another in a moment. Once painted, the bin belongs to this hh alone.

We cannot see the marbles' colors (that would require knowing ff), but we can see the handful we drew. The data contain both xn\mathbf{x}_n and yny_n; Lin adds a condition in the lecture: without noise, yny_n is simply f(xn)f(\mathbf{x}_n). Comparing h(xn)h(\mathbf{x}_n) with yny_n tells us whether the nn-th marble is orange or green. The handout's conclusion: if NN is large and the xn\mathbf{x}_n are i.i.d., we can probably infer the unknown probability of h(x)≠f(x)h(\mathbf{x}) \ne f(\mathbf{x}) by the known fraction of h(xn)≠ynh(\mathbf{x}_n) \ne y_n.

One component added to the flow diagram

Page 14 adds to the flow diagram of Foundations Lecture 1. The new piece is a box: an unknown probability distribution PP on X\mathcal{X}. Dashed lines connect it to two places:

  1. To the training examples, meaning x1,x2,…,xN\mathbf{x}_1, \mathbf{x}_2, \dots, \mathbf{x}_N are drawn from PP.
  2. To the judgment "is h≈fh \approx f?", meaning the x\mathbf{x} used to measure how good hh is also comes from the same PP.

Two solid lines also run to the judgment "is h≈fh \approx f?": one from the training examples and one from H\mathcal{H}, labeled fixed hh. What is being judged is one fixed hypothesis borrowed from H\mathcal{H}, and the judgment rests on the data. In the lecture, Lin says a dashed line marks something we do not know, and that using the same PP in two places corresponds to one and the same bin: the data are the handful drawn from the bin, and what we measure is the whole bin.

With PP in place, the two quantities can be defined formally. In the handout's notation:

Eout(h)=Ex∼P⟦h(x)≠f(x)⟧,Ein(h)=1N∑n=1N⟦h(xn)≠yn⟧E_{\text{out}}(h) = \mathop{\mathcal{E}}_{\mathbf{x} \sim P} \llbracket h(\mathbf{x}) \ne f(\mathbf{x}) \rrbracket, \qquad E_{\text{in}}(h) = \frac{1}{N}\sum_{n=1}^{N} \llbracket h(\mathbf{x}_n) \ne y_n \rrbracket

⟦⋅⟧\llbracket \cdot \rrbracket is this course's Boolean bracket: 1 if the statement inside holds and 0 if it does not. E\mathcal{E} is the expectation. So Eout(h)E_{\text{out}}(h) is the probability that hh is wrong on an x\mathbf{x} drawn from PP; it corresponds to μ\mu and is unknown. Ein(h)E_{\text{in}}(h) is the fraction of the NN examples on which hh is wrong; it corresponds to ν\nu and is known. In the lecture, Lin says "in" stands for in-sample, the errors within the sample in hand, and "out" for out-of-sample, the error rate beyond the sample, over the whole bin.

As an addition in this article: under this definition EoutE_{\text{out}} is an expectation over all of PP, so an input that already appeared in D\mathcal{D} still counts if it is drawn again. That is a different quantity from "counting only the inputs outside D\mathcal{D}": the No Free Lunch section counted the latter, looking only at the unseen 101, 110, and 111. The handout's summary page wraps up the marble section as probably approximately correct outside D\mathcal{D}, and in the lecture Lin also describes out-of-sample as the part beyond the sample, in the bin; those are the more colloquial phrasings, and the EoutE_{\text{out}} in the formulas follows the definition above. When the input space is large (for example, when the features are continuous values), the chance of drawing the same point again is negligible and the two quantities are almost equal. When there are only a few possible inputs they differ a lot, and "A world of eight inputs" below is computed over all of PP according to the definition.

The guarantee for one hypothesis

In the lecture, Lin says what follows is only a substitution of words. Replace ν\nu in Hoeffding with Ein(h)E_{\text{in}}(h) and μ\mu with Eout(h)E_{\text{out}}(h), and you have The Formal Guarantee of page 15. For any fixed hh:

P[ ∣Ein(h)−Eout(h)∣>ϵ ] ≤ 2exp⁡(−2ϵ2N)\mathbb{P}\big[\,\lvert E_{\text{in}}(h) - E_{\text{out}}(h) \rvert > \epsilon\,\big] \ \le\ 2\exp\big(-2\epsilon^2 N\big)

The properties the handout lists match the bin page one for one:

  • Valid for all NN and ϵ\epsilon.
  • The right side does not depend on Eout(h)E_{\text{out}}(h), so there is no need to know Eout(h)E_{\text{out}}(h); ff and PP can stay unknown.
  • "Ein(h)=Eout(h)E_{\text{in}}(h) = E_{\text{out}}(h)" is PAC.

On the second point, Lin explains in the lecture that we only assume ff and PP exist and do not actually need to know them; if we knew ff the game would be over and there would be nothing to learn.

At the bottom of the page is this section's chain of inference:

Ein(h)≈Eout(h)  and  Ein(h) small ⟹ Eout(h) small ⟹ h≈f  with respect to PE_{\text{in}}(h) \approx E_{\text{out}}(h) \ \text{ and } \ E_{\text{in}}(h) \text{ small} \ \Longrightarrow\ E_{\text{out}}(h) \text{ small} \ \Longrightarrow\ h \approx f \ \text{ with respect to } P

"With respect to PP" cannot be dropped. In the lecture, Lin says this is not an arbitrary guarantee: the data have to keep coming from the same PP for hh and ff to be close.

Verification is not learning

At this point it looks as if we could declare learning feasible. Page 16 asks: can we claim "good learning" (g≈fg \approx f)? In the lecture, Lin first reminds us that what the algorithm finally hands over is called gg, and hh is only one candidate in H\mathcal{H}. The handout's answer has two sides:

ConditionConclusion
YesEin(h)E_{\text{in}}(h) is small for the fixed hh, and A\mathcal{A} picks it as gg"g=fg = f" is PAC
NoA\mathcal{A} is forced to pick THE hh as ggEin(h)E_{\text{in}}(h) is almost always not small, so "g≠fg \ne f" is PAC

The cell on the right is the point. The derivation so far concerns one hh fixed in advance from start to finish. For the guarantee to hold, the algorithm would have to hand over the same hh no matter what the data look like. In the lecture, Lin explains that an algorithm returning the same hh whatever problem it meets will, nine times out of ten, return a poor hh with a large EinE_{\text{in}}. Hoeffding still holds then, and EinE_{\text{in}} and EoutE_{\text{out}} are still close; the conclusion you get is just that you can say with great confidence that gg is nothing like ff.

The handout's closing remark: real learning is A\mathcal{A} making choices in H\mathcal{H} (like PLA) rather than being forced to pick one hh. Lin uses PLA as the contrast in the lecture: give it different data and it returns a different line.

So what has been achieved so far goes by another name. Page 17 redraws the diagram as The 'Verification' Flow; compared with the learning flow:

PositionLearning flowVerification flow
Datatraining examplesverifying examples
Candidateshypothesis set H\mathcal{H}one hypothesis hh
Algorithm A\mathcal{A}present, does the choosingabsent, simply g=hg = h
Outputthe "learned" formulaa given formula that has been verified

In the handout's words: we can now use historical records to verify "one" candidate formula. Lin stresses in the lecture that these data have not been through learning and have not been through any selection procedure. That point becomes decisive in the section on many hypotheses.

A numerical example: a world of eight inputs

The setup and computations below were made up for this article and are not from the slides; they use the inputs and functions of the table on page 5 of the handout.

Setup. X={0,1}3\mathcal{X} = \{0,1\}^3, and PP is the uniform distribution giving each of the 8 inputs probability 1/81/8. The true target is f6f_6 from the table. The hypothesis hh is fixed in advance: on the first five inputs it gives the same answers as yy in the table, and on 101, 110, 111 it answers ○×○ (the gg of the student in the lecture).

Computing EoutE_{\text{out}}. f6f_6 is ×○× on 101, 110, 111, so hh is wrong on all three and right on the other five. Eout(h)=3/8=0.375E_{\text{out}}(h) = 3/8 = 0.375. In the real world this number cannot be seen; here we can compute it only because we built the whole world ourselves.

Sampling. Draw N=5N = 5 inputs independently from PP (repeats allowed); each lands where hh is wrong with probability 3/83/8. The number of errors kk follows a binomial distribution, and Ein(h)=k/5E_{\text{in}}(h) = k/5:

kkEin(h)E_{\text{in}}(h)Probability∣Ein−Eout∣\lvert E_{\text{in}} - E_{\text{out}}\rvertExceeds ϵ=0.3\epsilon = 0.3?
003125/32768≈0.09543125/32768 \approx 0.09540.375Yes
10.2≈0.2861\approx 0.28610.175No
20.4≈0.3433\approx 0.34330.025No
30.6≈0.2060\approx 0.20600.225No
40.8≈0.0618\approx 0.06180.425Yes
51≈0.0074\approx 0.00740.625Yes

Result. With ϵ=0.3\epsilon = 0.3, the probability of the bad event is 0.0954+0.0618+0.0074=0.16460.0954 + 0.0618 + 0.0074 = 0.1646 (exactly 5393/327685393/32768). The Hoeffding bound is 2exp⁡(−2×0.09×5)=2exp⁡(−0.9)≈0.8132\exp(-2 \times 0.09 \times 5) = 2\exp(-0.9) \approx 0.813. The exact value is below the bound.

What this means. First, N=5N = 5 is too small and a bound of 0.813 carries almost no information; Hoeffding needs a large NN to be useful. Second, the handout's D\mathcal{D} belongs to the k=0k = 0 row: all five examples fall where hh is right, Ein=0E_{\text{in}} = 0 looks perfect, and in fact Eout=0.375E_{\text{out}} = 0.375. For an hh fixed in advance, such a misleading sample turns up with a probability of only about 9.5%. But the gg in the handout's table was not fixed in advance; it was tuned to be all correct after looking at the data. That difference is dealt with in the numerical computations of the section "When the algorithm chooses, what the guarantee costs".

Fun Time: a friend's stock rule

Question (page 18): Your friend tells you her secret rule in investing in a particular stock: "Whenever the stock goes down in the morning, it will go up in the afternoon; vice versa." To verify the rule, you chose 100 days uniformly at random from the past 10 years of stock data, and found that 80 of them satisfy the rule. What is the best guarantee that you can get from the verification?

  1. You'll definitely be rich by exploiting the rule in the next 100 days.
  2. You'll likely be rich by exploiting the rule in the next 100 days, if the market behaves similarly to the last 10 years.
  3. You'll likely be rich by exploiting the "best rule" from 20 more friends in the next 100 days.
  4. You'd definitely have been rich if you had exploited the rule in the past 10 years.

Answer: 2. The handout gives one phrase for each of the other three options: option 1, no free lunch; option 3, no "learning" guarantee in verification; option 4, verifying with only 100 days, it is possible that the rule is mostly wrong for the whole 10 years.

This article runs the question through this section's correspondence. The rule is a fixed hh (she stated it before you picked the days); the bin is every day of the past 10 years, and PP is the uniform distribution over those days; the 100 days are a sample with N=100N = 100; 80 days satisfy the rule, so Ein(h)=0.2E_{\text{in}}(h) = 0.2. Treating the 100 days as drawn independently and taking ϵ=0.15\epsilon = 0.15:

2exp⁡(−2×0.152×100)=2exp⁡(−4.5)≈0.0222\exp\big(-2 \times 0.15^2 \times 100\big) = 2\exp(-4.5) \approx 0.022

So with at least 97.8% confidence, the rule's error rate over the 10 years is no more than 0.2+0.15=0.350.2 + 0.15 = 0.35, meaning at least 65% of the days satisfy it. This is a "likely" guarantee, and what it is about is the bin of the past 10 years.

  • Option 2 is right in two places: it says "likely" rather than "definitely", and it adds "the market behaves similarly to the last 10 years", meaning future days come from the same PP. That is exactly the final "with respect to PP" of the chain of inference.
  • Option 1 is wrong because of "definitely", and it lacks the premise that the future resembles the past. Without that premise the next 100 days are inputs outside D\mathcal{D}, and anything can happen.
  • Option 4 is also wrong because of "definitely". In the lecture, Lin explains that the 100 days drawn might look quite unlike the distribution over the 10 years; that is the kind of sample in the k=0k = 0 row of the table above.
  • Option 3 mistakes verification for learning. You verified this one rule and none of the others; even if you checked all 21 rules against the same 100 days and then picked the best, that would already be making a choice. In the lecture, Lin says that picking one rule out of 20 does not necessarily come with a guarantee this strong. How much weaker is something the section "When the algorithm chooses, what the guarantee costs" can compute.

When the algorithm chooses, what the guarantee costs

YouTube:Feasibility of Learning :: Connection to Real Learning @ Machine Learning Foundations (機器學習基石)

(Video 00:00–01:17 is the many bins, 01:17–04:23 is coin flipping, 04:23–06:57 defines BAD, 06:57–09:59 is BAD data with many hypotheses, 09:59–12:16 is the union bound, 12:16–15:00 is the learning flow and the problem of infinite M, and Fun Time and the summary follow.)

Many bins

Page 19 draws MM bins, one per hypothesis: the orange fraction in the bin of h1h_1 is Eout(h1)E_{\text{out}}(h_1), the orange fraction in its sample is Ein(h1)E_{\text{in}}(h_1), and so on down the row to hMh_M. In the figure, the 10 marbles drawn from the bin of hMh_M are all green. The bottom of the page asks: in real learning (say like PLA), is it BINGO when you get all green?

In the lecture, Lin spells the question out: 10 hypotheses are 10 bins, and one bin yielding all green marbles corresponds to one hypothesis being fully correct on the data you see. Should you choose it?

Coin flipping: with choice, rare things stop being rare

Page 20 answers with coins. Q: if everyone in the size-150 NTU ML class flips a coin 5 times, and one of the students gets 5 heads for her coin "gg", is "gg" really magical?

A: No. Even if all coins are fair, the probability that one of the 150 coins results in 5 heads is

1−(3132)150>99%1 - \Big(\frac{31}{32}\Big)^{150} > 99\%

Derivation: a fair coin flipped 5 times comes up all heads with probability (1/2)5=1/32(1/2)^5 = 1/32, so the probability of "not" all heads is 31/3231/32. The 150 coins are independent, so the probability that none of the 150 is all heads is (31/32)150≈0.0085(31/32)^{150} \approx 0.0085. Subtracting from 1, the probability that at least one is all heads is about 0.9915.

In the lecture, Lin adds a version you can try at home: one person at a computer can run the 150 rounds alone, and all heads usually turns up within 20, 30, or 40 rounds. This article checks: the probability of it appearing within 20 rounds is 1−(31/32)20≈0.471 - (31/32)^{20} \approx 0.47, within 30 rounds 0.61, within 40 rounds 0.72; from round 22 on it exceeds one half.

The correspondence with learning: a coin is a hypothesis, the 5 flips are 5 examples, heads means correct, and a fair coin has Eout=1/2E_{\text{out}} = 1/2. All heads is Ein=0E_{\text{in}} = 0. Picking out the all-heads coin amounts to picking the hypothesis with the smallest EinE_{\text{in}}, and its EoutE_{\text{out}} is still 1/21/2. Lin's conclusion in the lecture is that choice brings bias, even though these coins are all the same. For a single coin the probability of all heads is 1/321/32; with 150 to choose from, the probability exceeds 99%. In the handout's words: BAD sample means EinE_{\text{in}} and EoutE_{\text{out}} far away, and it can get worse when involving "choice".

BAD sample and BAD data

Page 21 defines "bad" precisely:

  • BAD sample: e.g., Eout=1/2E_{\text{out}} = 1/2, but getting all heads (Ein=0E_{\text{in}} = 0).
  • BAD data for one hh: Eout(h)E_{\text{out}}(h) and Ein(h)E_{\text{in}}(h) far away. The typical case the handout gives is EoutE_{\text{out}} big (far from ff) but EinE_{\text{in}} small (correct on most examples).

In the lecture, Lin supplies the standard for "far": differing by more than ϵ\epsilon.

The handout then draws a one-row table. Line up all the data sets that could possibly be drawn, D1,D2,…,D1126,…,D5678,…\mathcal{D}_1, \mathcal{D}_2, \dots, \mathcal{D}_{1126}, \dots, \mathcal{D}_{5678}, \dots, each one NN examples. For a fixed hh, each cell either is BAD or is not. In the handout's figure, the row of hh is BAD at D1\mathcal{D}_1 and D5678\mathcal{D}_{5678}. The probability of BAD is a sum over all possible data sets:

PD[BAD D]=∑all possible DP(D)⋅⟦BAD D⟧\mathbb{P}_{\mathcal{D}}\big[\text{BAD } \mathcal{D}\big] = \sum_{\text{all possible } \mathcal{D}} \mathbb{P}(\mathcal{D}) \cdot \llbracket \text{BAD } \mathcal{D} \rrbracket

Hoeffding says this sum is small. In the lecture, Lin repeats several times where the probability lives: on the act of drawing a handful. What Hoeffding guarantees is that the BAD cells in this row add up to a small probability; whether the data set in your hands is BAD, it does not say.

What counts as bad with many hypotheses

Page 22 extends the table to many rows, one per hypothesis. The table in the handout:

D1\mathcal{D}_1D2\mathcal{D}_2…D1126\mathcal{D}_{1126}…D5678\mathcal{D}_{5678}Hoeffding
h1h_1BADBADPD[BAD D for h1]≤…\mathbb{P}_{\mathcal{D}}[\text{BAD } \mathcal{D} \text{ for } h_1] \le \dots
h2h_2BADPD[BAD D for h2]≤…\mathbb{P}_{\mathcal{D}}[\text{BAD } \mathcal{D} \text{ for } h_2] \le \dots
h3h_3BADBADBADPD[BAD D for h3]≤…\mathbb{P}_{\mathcal{D}}[\text{BAD } \mathcal{D} \text{ for } h_3] \le \dots
…
hMh_MBADBADPD[BAD D for hM]≤…\mathbb{P}_{\mathcal{D}}[\text{BAD } \mathcal{D} \text{ for } h_M] \le \dots
allBADBADBAD?

Each row has its own Hoeffding watching over it, and its BAD cells add up to a small probability. What is new is the bottom row. The handout's definition uses two equivalent statements:

BAD data for many h  ⟺  no ’freedom of choice’ by A  ⟺  there exists some h such that Eout(h) and Ein(h) far away\text{BAD data for many } h \iff \text{no 'freedom of choice' by } \mathcal{A} \iff \text{there exists some } h \text{ such that } E_{\text{out}}(h) \text{ and } E_{\text{in}}(h) \text{ far away}

In other words, one BAD cell anywhere in a column makes that data set BAD for the whole of H\mathcal{H}. Lin's analogy in the lecture is stepping on a landmine: good data let the algorithm choose however it likes and still be right; bad data have a mine buried in them, the algorithm sees some hypothesis with a low EinE_{\text{in}} and chooses it, and its EoutE_{\text{out}} turns out to be large. Lin reads off the table in the lecture: with D1\mathcal{D}_1, the mines you might step on are h1h_1, h3h_3, and hMh_M; with D2\mathcal{D}_2, the mines are h2h_2 and h3h_3; only something like D1126\mathcal{D}_{1126}, with no mine in the whole column, is good data.

The question mark at the lower right is what this section sets out to compute: for MM hypotheses, what is the bound of PD[BAD D]\mathbb{P}_{\mathcal{D}}[\text{BAD } \mathcal{D}]?

The union bound: a four-line derivation

The derivation on page 23 has only four lines. Take them one at a time.

Line one: write the definition as an "or". BAD is defined as some hypothesis going wrong, so

PD[BAD D]=PD[BAD D for h1 or BAD D for h2 or … or BAD D for hM]\mathbb{P}_{\mathcal{D}}\big[\text{BAD } \mathcal{D}\big] = \mathbb{P}_{\mathcal{D}}\big[\text{BAD } \mathcal{D} \text{ for } h_1 \ \textbf{or} \ \text{BAD } \mathcal{D} \text{ for } h_2 \ \textbf{or} \ \dots \ \textbf{or} \ \text{BAD } \mathcal{D} \text{ for } h_M\big]

Line two: split the "or" into a sum. This step is called the union bound:

≤ PD[BAD D for h1]+PD[BAD D for h2]+⋯+PD[BAD D for hM]\le\ \mathbb{P}_{\mathcal{D}}\big[\text{BAD } \mathcal{D} \text{ for } h_1\big] + \mathbb{P}_{\mathcal{D}}\big[\text{BAD } \mathcal{D} \text{ for } h_2\big] + \dots + \mathbb{P}_{\mathcal{D}}\big[\text{BAD } \mathcal{D} \text{ for } h_M\big]

Why "less than or equal to": in the lecture, Lin explains it with the areas of sets; the area of a union of several sets cannot exceed the sum of their individual areas. This article adds the two-event version: P[A or B]=P[A]+P[B]−P[A and B]\mathbb{P}[A \text{ or } B] = \mathbb{P}[A] + \mathbb{P}[B] - \mathbb{P}[A \text{ and } B], where the last term is never negative, and dropping it gives P[A or B]≤P[A]+P[B]\mathbb{P}[A \text{ or } B] \le \mathbb{P}[A] + \mathbb{P}[B]. The overlap is counted twice, so adding directly can only overshoot, never undershoot. This step does not require the events to be independent.

Line three: apply Hoeffding once to each term. Every hmh_m is a fixed hypothesis that was sitting in H\mathcal{H} before the data were drawn, so "the guarantee for one hypothesis" holds for it:

≤ 2exp⁡(−2ϵ2N)+2exp⁡(−2ϵ2N)+⋯+2exp⁡(−2ϵ2N)\le\ 2\exp\big(-2\epsilon^2 N\big) + 2\exp\big(-2\epsilon^2 N\big) + \dots + 2\exp\big(-2\epsilon^2 N\big)

Line four: add up MM identical numbers.

= 2Mexp⁡(−2ϵ2N)=\ 2M\exp\big(-2\epsilon^2 N\big)

The handout calls it the finite-bin version of Hoeffding and lists three points:

  • Valid for all MM, NN, and ϵ\epsilon.
  • No need to know any Eout(hm)E_{\text{out}}(h_m); ff and PP can stay unknown.
  • "Ein(g)=Eout(g)E_{\text{in}}(g) = E_{\text{out}}(g)" is PAC, regardless of A\mathcal{A}.

The third point is where the whole lecture lands. The handout states only the conclusion; this article fills in the reason. The gg the algorithm hands over is one of h1,…,hMh_1, \dots, h_M, and which one depends on the data. If this D\mathcal{D} is not BAD, then every hmh_m has EinE_{\text{in}} and EoutE_{\text{out}} within ϵ\epsilon of each other, so whichever one the algorithm picks, gg is within ϵ\epsilon too. Put the other way round, "EinE_{\text{in}} and EoutE_{\text{out}} of gg differ by more than ϵ\epsilon" can only happen on a BAD D\mathcal{D}:

PD[ ∣Ein(g)−Eout(g)∣>ϵ ] ≤ PD[BAD D] ≤ 2Mexp⁡(−2ϵ2N)\mathbb{P}_{\mathcal{D}}\big[\,\lvert E_{\text{in}}(g) - E_{\text{out}}(g) \rvert > \epsilon\,\big] \ \le\ \mathbb{P}_{\mathcal{D}}\big[\text{BAD } \mathcal{D}\big] \ \le\ 2M\exp\big(-2\epsilon^2 N\big)

Where "Verification is not learning" got stuck was that gg has seen the data and is not fixed. The fix here is to stop tracking which one the algorithm will pick and require every candidate to be safe at once. As Lin puts it in the lecture, when every hh is safe the algorithm can choose any way it likes. The price is an extra MM on the right side; Lin's example is a hypothesis set of 100 hypotheses, where the bound on the probability of the bad event is 100 times the original.

Since any choice is safe, the handout says the most reasonable A\mathcal{A} (like PLA or pocket) picks the one with the lowest Ein(hm)E_{\text{in}}(h_m) as gg. Lin's reason in the lecture: every hypothesis has EinE_{\text{in}} and EoutE_{\text{out}} close together, so the one with the smallest EinE_{\text{in}} will have an EoutE_{\text{out}} on the smaller side as well.

As an addition in this article: in the coin example the 150 coins are independent, which is why the exact 1−(31/32)1501 - (31/32)^{150} can be computed. In a learning problem the MM hypotheses all look at the same data, their BAD events are correlated with one another, and the exact value is hard to compute; the union bound does not need independence, and that is why it is used. It can also be very loose: applied to the coins, the union bound gives 150×1/32≈4.69150 \times 1/32 \approx 4.69, larger than 1.

Plugging in numbers

The computations below belong to this article and continue the two made-up scenarios from earlier.

The stock rule, one picked out of 21. You check your friend's rule and the rules of 20 more friends against the same 100 days and pick the rule that the most days satisfy. M=21M = 21, N=100N = 100:

ϵ\epsilonOne rule: 2exp⁡(−2ϵ2N)2\exp(-2\epsilon^2 N)One picked out of 21: 2×21×exp⁡(−2ϵ2N)2 \times 21 \times \exp(-2\epsilon^2 N)
0.100.2715.68
0.150.0220.467
0.200.000670.0141

When only one rule is verified, ϵ=0.15\epsilon = 0.15 already gives 97.8% confidence. After choosing, the same ϵ\epsilon leaves only 53.3% confidence; to get back to roughly the same confidence level, ϵ\epsilon has to be relaxed to 0.2. With the same "80 of 100 days satisfy it", for one rule you can say the error rate is likely no more than 0.35, and for the one picked out of 21 you can only say it is likely no more than 0.4. The guarantee is still there, only weaker.

How much data is needed. Require 2Mexp⁡(−2ϵ2N)≤δ2M\exp(-2\epsilon^2 N) \le \delta and rearrange as before:

N ≥ 12ϵ2ln⁡2MδN \ \ge\ \frac{1}{2\epsilon^2}\ln\frac{2M}{\delta}

MM sits inside the logarithm. With ϵ=0.1\epsilon = 0.1 and δ=0.05\delta = 0.05: M=1M = 1 needs 185 examples, M=100M = 100 needs 415, and M=106M = 10^6 needs 876. Ten thousand times as many hypotheses takes only about twice as much data. That is the good news for finitely many hypotheses.

Back to the world of eight inputs. Page 4 of the handout puts all 256 functions into H\mathcal{H}, with N=5N = 5. With ϵ=0.3\epsilon = 0.3 the bound is 2×256×exp⁡(−0.9)≈2082 \times 256 \times \exp(-0.9) \approx 208, far above 1 and no guarantee at all. Here the truth can also be computed directly: whichever 5 examples are drawn, they cover at most 5 distinct inputs, and at least 3 are never drawn. Among the 256 functions there is always one that agrees with ff on every drawn input and disagrees on every undrawn one, with Ein=0E_{\text{in}} = 0 and Eout≥3/8=0.375>0.3E_{\text{out}} \ge 3/8 = 0.375 > 0.3. So every possible D\mathcal{D} is BAD, and PD[BAD D]=1\mathbb{P}_{\mathcal{D}}[\text{BAD } \mathcal{D}] = 1.

This connects the No Free Lunch section to the three sections on probability that follow it. Retold in the language of probability, the No Free Lunch example is the case where MM is too large and NN too small, so the union bound exceeds 1. Conversely, if the candidates are restricted in advance to 2 hypotheses and there are N=50N = 50 independently drawn examples, the same ϵ=0.3\epsilon = 0.3 gives 2×2×exp⁡(−9)≈0.00052 \times 2 \times \exp(-9) \approx 0.0005. The condition for learning to be feasible is that the candidates cannot be too many and the data must be plentiful, the two tied together by the expression 2Mexp⁡(−2ϵ2N)2M\exp(-2\epsilon^2 N).

The condition for feasibility, and what remains unsolved

Page 24 writes the conclusion as The 'Statistical' Learning Flow:

  • If ∣H∣=M\lvert\mathcal{H}\rvert = M is finite and NN is large enough, then for whatever gg picked by A\mathcal{A}, Eout(g)≈Ein(g)E_{\text{out}}(g) \approx E_{\text{in}}(g).
  • If A\mathcal{A} finds one gg with Ein(g)≈0E_{\text{in}}(g) \approx 0, there is a PAC guarantee for Eout(g)≈0E_{\text{out}}(g) \approx 0, and learning is possible.

Compared with Foundations Lecture 1, Lin says in the lecture, the flow diagram has only two more lines, both starting from the unknown PP: one generates x1,…,xN\mathbf{x}_1, \dots, \mathbf{x}_N of the training examples, and one generates the x\mathbf{x} used to test g≈fg \approx f.

The lower right of the diagram leaves a question: what about M=∞M = \infty (like perceptrons)? There are infinitely many lines in the plane, and 2Mexp⁡(−2ϵ2N)2M\exp(-2\epsilon^2 N) becomes infinite outright. In the lecture, Lin voices the students' objection for them: after all this, H\mathcal{H} still has to be finite, so isn't it all just talk? The reply is that it is indeed not fully solved yet, but the finite case is a very good starting point; the infinite case is somewhat difficult and will take roughly the next two to three class sessions.

The summary on page 26 reduces each of the four sections to one line, and the order is the argument of this lecture:

  1. Learning is Impossible?: absolutely no free lunch outside D\mathcal{D}.
  2. Probability to the Rescue: probably approximately correct outside D\mathcal{D}.
  3. Connection to Learning: verification possible if Ein(h)E_{\text{in}}(h) small for fixed hh.
  4. Connection to Real Learning: learning possible if ∣H∣\lvert\mathcal{H}\rvert finite and Ein(g)E_{\text{in}}(g) small.

Fun Time: BAD data of four hypotheses

Question (page 25): Consider 4 hypotheses:

h1(x)=sign(x1),h2(x)=sign(x2),h3(x)=sign(−x1),h4(x)=sign(−x2)h_1(\mathbf{x}) = \text{sign}(x_1), \quad h_2(\mathbf{x}) = \text{sign}(x_2), \quad h_3(\mathbf{x}) = \text{sign}(-x_1), \quad h_4(\mathbf{x}) = \text{sign}(-x_2)

For any NN and ϵ\epsilon, which of the following statements is "not" true?

  1. the BAD data of h1h_1 and the BAD data of h2h_2 are exactly the same
  2. the BAD data of h1h_1 and the BAD data of h3h_3 are exactly the same
  3. PD[BAD for some hk]≤8exp⁡(−2ϵ2N)\mathbb{P}_{\mathcal{D}}[\text{BAD for some } h_k] \le 8\exp(-2\epsilon^2 N)
  4. PD[BAD for some hk]≤4exp⁡(−2ϵ2N)\mathbb{P}_{\mathcal{D}}[\text{BAD for some } h_k] \le 4\exp(-2\epsilon^2 N)

Answer: 1. The handout's solution is two sentences: the important thing is to note that option 2 is true, which implies that option 4 is true if you revisit the union bound; similar ideas will be used to conquer the M=∞M = \infty case.

Why option 2 is true. h3=−h1h_3 = -h_1, so the two give opposite answers at every point. Where h1h_1 is right h3h_3 is wrong and vice versa, so

Ein(h3)=1−Ein(h1),Eout(h3)=1−Eout(h1)E_{\text{in}}(h_3) = 1 - E_{\text{in}}(h_1), \qquad E_{\text{out}}(h_3) = 1 - E_{\text{out}}(h_1)

Subtracting gives Ein(h3)−Eout(h3)=−(Ein(h1)−Eout(h1))E_{\text{in}}(h_3) - E_{\text{out}}(h_3) = -\big(E_{\text{in}}(h_1) - E_{\text{out}}(h_1)\big), with the same absolute value. A data set that is BAD for h1h_1 is BAD for h3h_3 as well. This is Lin's explanation in the lecture: multiply a hypothesis by a minus sign and both EinE_{\text{in}} and EoutE_{\text{out}} flip relative to it, so they stay equally far apart. (At points where x1x_1 is exactly 0 both are sign(0)\text{sign}(0); that case is not discussed here.)

Option 3 is true. It is just M=4M = 4 plugged into 2Mexp⁡(−2ϵ2N)2M\exp(-2\epsilon^2 N).

Option 4 is true as well. By the same argument h2h_2 and h4h_4 have the same BAD data. The four events are really only two distinct events, the first line of the derivation becomes "BAD for h1h_1 or BAD for h2h_2", and the union bound needs only two terms: 2×2exp⁡(−2ϵ2N)=4exp⁡(−2ϵ2N)2 \times 2\exp(-2\epsilon^2 N) = 4\exp(-2\epsilon^2 N).

Why option 1 is not true. h1h_1 looks at the first coordinate and h2h_2 at the second; they are wrong at different points, and there is no reason for them to go wrong on the same data. Here is a counterexample made up for this article, not from the slides, that can be worked by hand. PP is the uniform distribution on the four points (+1,+1)(+1,+1), (+1,−1)(+1,-1), (−1,+1)(-1,+1), (−1,−1)(-1,-1), and ff is +1+1 on the first three points and −1-1 on (−1,−1)(-1,-1). Then h1h_1 is wrong only at (−1,+1)(-1,+1), h2h_2 is wrong only at (+1,−1)(+1,-1), and both have EoutE_{\text{out}} equal to 1/41/4. Take N=2N = 2 and ϵ=0.3\epsilon = 0.3, drawing two points in order for 16 equally likely data sets. EinE_{\text{in}} can only be 0, 1/21/2, or 1. For h1h_1 and h2h_2, the only value more than 0.3 away from Eout=1/4E_{\text{out}} = 1/4 is Ein=1E_{\text{in}} = 1, which means both draws hit the point where the hypothesis is wrong. h3h_3 and h4h_4 have EoutE_{\text{out}} equal to 3/43/4, and the only value more than 0.3 away is Ein=0E_{\text{in}} = 0, which means both draws hit the single point where the hypothesis is right: for h3h_3 that point is (−1,+1)(-1,+1), and for h4h_4 it is (+1,−1)(+1,-1).

HypothesisBAD data setsProbability
h1h_1both draws are (−1,+1)(-1,+1)1/161/16
h2h_2both draws are (+1,−1)(+1,-1)1/161/16
h3h_3both draws are (−1,+1)(-1,+1)1/161/16
h4h_4both draws are (+1,−1)(+1,-1)1/161/16

The BAD data of h1h_1 and of h2h_2 are two different data sets, so option 1 is not true; those of h1h_1 and h3h_3 are the same data set, so option 2 is true. The probability that at least one hypothesis goes wrong is 2/162/16, while adding the four rows directly gives 4/164/16; the excess is exactly the overlap counted twice. The NN in this example is too small and the Hoeffding number itself exceeds 1; the example only serves to show how the sets relate.

In the lecture, Lin says this question is slightly harder and is there to get everyone thinking about BAD events overlapping; the next lecture uses this property to discuss the case of infinitely many lines.

Self-check

1. A hypothesis fixed in advance measures Ein=0.08E_{\text{in}} = 0.08 on N=500N = 500 independently drawn examples. With ϵ=0.05\epsilon = 0.05, what is the Hoeffding bound? If this hypothesis was the one with the lowest EinE_{\text{in}} among 20 candidates, what does the bound become? How many examples are needed for the probability of the bad event to be at most 0.05 with 20 candidates and ϵ=0.05\epsilon = 0.05?

Answer: for one hypothesis, 2exp⁡(−2×0.0025×500)=2exp⁡(−2.5)≈0.1642\exp(-2 \times 0.0025 \times 500) = 2\exp(-2.5) \approx 0.164, so with 83.6% confidence EoutE_{\text{out}} lies between 0.03 and 0.13. With 20 candidates, multiply by 20 to get 3.28, which exceeds 1 and guarantees nothing. N≥ln⁡(2×20/0.05)/(2×0.0025)=ln⁡800/0.005≈1336.9N \ge \ln(2 \times 20 / 0.05) / (2 \times 0.0025) = \ln 800 / 0.005 \approx 1336.9, so 1,337 examples are needed.

2. Explain in your own words: why can Hoeffding's inequality not be applied directly to the gg that PLA finds?

Criteria: the answer should mention three things. First, painting marbles orange or green requires a fixed hh beforehand, and the bin belongs to that hh alone. Second, gg is decided after looking at the data, and a different data set gives a different gg, so it is not a hypothesis fixed in advance. Third, the remedy is to require every candidate in H\mathcal{H} to be safe at once, paying a factor of MM through the union bound. Answering only "because gg is not fixed" without saying why being fixed matters is not complete.

3. In a class of 60, everyone flips a fair coin 6 times. What is the probability that at least one person gets heads all 6 times? What upper bound does the union bound give?

Answer: one person gets all heads with probability 1/641/64. The probability that at least one person gets all heads is 1−(63/64)60≈0.6111 - (63/64)^{60} \approx 0.611. The union bound gives 60×1/64=0.937560 \times 1/64 = 0.9375. The bound is indeed larger than the exact value, and the gap comes from double counting the cases where two or more people get all heads at once.

4. X={0,1}4\mathcal{X} = \{0,1\}^4, and the data D\mathcal{D} give the answers for 10 distinct inputs, without noise. How many target functions are fully consistent with D\mathcal{D}? For some gg that is correct on all of D\mathcal{D}, how many of the inputs outside D\mathcal{D} does it get right on average (averaging over all consistent target functions)?

Answer: X\mathcal{X} has 24=162^4 = 16 inputs, 6 remain outside D\mathcal{D}, and each has 2 possible answers, so there are 26=642^6 = 64 consistent target functions. For each unseen input, exactly half of the 64 functions say ○ and half say ×, so whatever gg guesses it matches only half of them, and on average it gets 6×1/2=36 \times 1/2 = 3 right, the same as random guessing.

5. A hypothesis set has 100 hypotheses that form exactly 50 pairs of "hh and −h-h". Can the bound on PD[BAD D]\mathbb{P}_{\mathcal{D}}[\text{BAD } \mathcal{D}] be written smaller than 200exp⁡(−2ϵ2N)200\exp(-2\epsilon^2 N)?

Answer: yes. hh and −h-h have exactly the same BAD data, so the 100 events contain only 50 distinct events, the union bound needs only 50 terms, and the bound is 2×50×exp⁡(−2ϵ2N)=100exp⁡(−2ϵ2N)2 \times 50 \times \exp(-2\epsilon^2 N) = 100\exp(-2\epsilon^2 N). Criteria: the answer should say that when BAD events overlap, adding them directly double counts.

Exercises and corresponding reading

Check the numbers yourself. Every number in this lecture can be recomputed with the Python standard library, with no packages to install. The snippet below computes the exact values first and then compares against a simulation:

import random
from math import comb, exp

# Fun Time: mu = 0.4, draw 10 marbles, nu <= 0.1
exact = sum(comb(10, k) * 0.4**k * 0.6**(10 - k) for k in (0, 1))
bound = 2 * exp(-2 * 0.3**2 * 10)
print(f"exact {exact:.4f}  Hoeffding bound {bound:.4f}")

# Coin flipping: 150 people flip 5 times each, at least one gets all heads
print(f"exact {1 - (31 / 32) ** 150:.4f}")
random.seed(0)
trials = 10_000
hits = sum(
    any(all(random.random() < 0.5 for _ in range(5)) for _ in range(150))
    for _ in range(trials)
)
print(f"simulated {hits / trials:.4f}")

The first two lines of output should be exact 0.0464 Hoeffding bound 0.3306 and exact 0.9915, and the simulated value will land near 0.99. You can then change the NN in the marble part to 100 and 1,000 and watch how the gap between the exact value and the bound changes.

How the two semesters line up. The Fall 2026 course page lists this lecture among the required pre-class viewing for W3, with the textbook section given as Learning from Data (LFD) 1.3. Both the Fall 2026 and Fall 2024 course pages list a further reading next to this lecture: Wolpert's The Lack of A Priori Distinctions Between Learning Algorithms (Neural Computation, 1996), the original No Free Lunch paper. The above was checked on 2026-09-30.

What the Fall 2026 extended slides (04e) add. Three things are not in the MOOC handout:

  • Another demonstration of No Free Lunch with the sequence 1, 4, 1, 5: the same first four terms can be continued by three different recurrences into three different next terms, and the slide's phrase is any number can be the next.
  • A rough one-sentence statement of Wolpert's 1996 No Free Lunch theorem: with no assumption about the learning problem, all learning algorithms perform the same.
  • The last page draws the MM hypotheses as MM bins sharing the same x1,…,xN\mathbf{x}_1, \dots, \mathbf{x}_N and stresses that this is dependent sampling: the hypotheses' BAD events are correlated rather than independent like the coin flips, so they are hard to analyze directly, and the union bound is the conservative approach.

Homework. Both sets are public, have no official solutions, and are graded only for enrolled students.

The "Feasibility of Learning" part of Fall 2026 hw1 (due 10/21):

  • Q6: off-training-set error. Pick any 3 points of a 6-point universe as D\mathcal{D}, reach Ein=0E_{\text{in}} = 0 with a perceptron, and ask for the smallest and largest error rate outside D\mathcal{D}. This is a direct drill on the No Free Lunch table.
  • Q7: estimate π\pi by Monte Carlo dart throwing; how many darts are needed for the probability that the error is within 10−210^{-2} to exceed 0.999? The method is to solve Hoeffding in reverse for NN.
  • Q8–9: compute EoutE_{\text{out}} of two hypotheses on [−1,+1]2[-1, +1]^2, then the probability that their EinE_{\text{in}} are equal when 4 points are drawn. The problem notes that this is BAD data that cannot tell which hypothesis is worse.
  • Q10: multiple-bin sampling with dice in place of marbles. Each number is a hypothesis and each die is an example; the question is the probability that "some number is all green" when 5 dice are drawn.

Fall 2024 HW2 covers Lectures 4 through 7; the problems that practice this lecture are:

  • Q2: 16 bags of cards, half black and half white, with 5 cards drawn from each; the probability that at least one hand is all white. This is the independent version of coin flipping.
  • Q5: critique ChatGPT's answer to "given that the first N−1N - 1 terms come from some polynomial of degree NN, can the next term be predicted?", which practices the No Free Lunch argument.
  • Q6–7: a multiple-bin game with four kinds of lottery tickets; the problem hints that each number be seen as a hypothesis and the drawn tickets as the data, and states that Q6 must take dependent sampling into account.
  • Q8: MM slot machines; starting from one-sided Hoeffding, prove that the upper confidence bounds of all machines at all time steps hold simultaneously with probability at least 1−δ1 - \delta. The problem hints that this is the core technique of the upper-confidence bound algorithm for the multi-armed bandit, and what it uses is exactly this lecture's union bound.

Without solutions, the most direct self-check for a probability problem is simulation: simulate the number first, then go back and check the derivation. The guide to the whole homework set is in the Foundations homework guide.

Further reading. Caltech Learning from Data is the English-language course for the same textbook; Lecture 2: Is Learning Feasible? corresponds to this lecture. The Stanford CS229 guide presents learning theory in a different way.

Next lecture. Foundations Lecture 5: Training versus Testing starts from the observation in the last Fun Time question: the BAD data of many hypotheses overlap, and the union bound counts them more than once. Once the overlap is accounted for, an infinite MM has a chance of being replaced by a finite number.

Course video sources

Original videos: Learning is Impossible?, Probability to the Rescue, Connection to Learning, Connection to Real Learning

Checked: 2026-10-13. The video IDs, titles, and lengths were taken from the official playlist that day; the videos have no caption tracks on YouTube, and what this article reports from the lecture comes from transcripts made for it.

Update Log

  • 2026-10-13: The whole series was changed to one article per lecture. This article already covered only Lecture 4; this time it was rewritten from the handout and the video transcripts, adding the derivations of the four sections, explanations of the four Fun Time questions, and numerical examples.
  • 2026-10-10: Marked the video status and checked the recording sources and how they were obtained.
  • 2026-10-10: Rechecked the video status. The embedded videos match the lecture numbers in the official playlist.

References