🌏 中文版
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 (, , , , ), 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 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
(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 , the three in the bottom row , and the question is what 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 " / ":
| Picture | Label | Three rows (top to bottom) | Black cells |
|---|---|---|---|
| Top left | ■□□ / ■□■ / □■□ | 4 | |
| Top middle | ■□□ / □□■ / ■□■ | 4 | |
| Top right | ■□□ / □□■ / □□□ | 2 | |
| Bottom left | □□■ / □■□ / ■□□ | 3 | |
| Bottom middle | □■□ / ■□■ / □■□ | 4 | |
| Bottom right | □■■ / ■■□ / □■■ | 6 | |
| Picture to predict | ? | ■□□ / □■□ / □□■ | 3 |
Page 3 is titled Two Controversial Answers and lists four rules, each of which classifies all six pictures correctly:
| Rule | On the six pictures | On the seventh picture |
|---|---|---|
| symmetry ⇔ | Each of the three bottom pictures has an axis of symmetry; none of the three top ones does | Symmetric about the diagonal, |
| (black or white count = 3) or (black count = 4 and middle-top black) ⇔ | Bottom row: 3 black; 4 black with middle-top black; 3 white. None of the top row qualifies | 3 black cells, |
| left-top black ⇔ | The left-top cell is black in every top picture and white in every bottom picture | Left-top is black, |
| middle column contains at most 1 black and right-top white ⇔ | All three top pictures qualify; none of the three bottom ones does | 1 black in the middle column and right-top white, |
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 for the seventh picture, and the last two say .
In the lecture this becomes a dialogue. If the student answers , the teacher says the rule in mind was symmetry and the answer is ; if the student answers , the teacher says the rule in mind was the left-top cell and the answer is . 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, , 8 possible inputs in all; the output is . The data give the answers for 5 of those inputs:
| 000 | ○ |
| 001 | × |
| 010 | × |
| 011 | ○ |
| 100 | × |
With 8 inputs and 2 possible outputs for each, there are functions from to . The handout says we can then enumerate all candidate as ; 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 that is correct on all 5 examples, that is, all . 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 resembles .
Page 5 lays the answer out as a table. The inputs does not cover are 101, 110, and 111; the true answer on each can be ○ or ×, so there are target functions fully consistent with , which the handout calls through :
| 000 | ○ | ○ | ○ | ○ | ○ | ○ | ○ | ○ | ○ | ○ |
| 001 | × | × | × | × | × | × | × | × | × | × |
| 010 | × | × | × | × | × | × | × | × | × | × |
| 011 | ○ | ○ | ○ | ○ | ○ | ○ | ○ | ○ | ○ | ○ |
| 100 | × | × | × | × | × | × | × | × | × | × |
| 101 | ? | ○ | ○ | ○ | ○ | × | × | × | × | |
| 110 | ? | ○ | ○ | × | × | ○ | ○ | × | × | |
| 111 | ? | ○ | × | ○ | × | ○ | × | ○ | × |
The first five rows are : the eight look identical there, and the algorithm has tuned to match. The handout's two-line conclusion:
- inside : sure!
- outside : No! (but that's really what we want!)
In the lecture, Lin walks through the last three rows with a concrete : suppose your predicts ○×○ on 101, 110, and 111. In the worst case the true happens to be ×○× ( in the table), and all three are wrong.
As an addition in this article, count this against each of the eight . The number of the three new inputs it gets right, for through in order, is 2, 1, 3, 2, 1, 0, 2, 1, a total of 12 and an average of , exactly half. Any other 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 . 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 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 (to infer something outside ) is doomed if any "unknown" 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 is unknown; if we insist on only that and assume nothing else, we cannot say whether 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 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 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":
It is like a "learning problem" with , , . Learn a hypothesis from the one example to predict on . What is your answer?
- 151026
- 143547
- I need more examples to get the correct answer
- 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 , the next two digits are , and the last two digits are . Checking: gives 15, 10, and , which concatenate to 151022; gives 14, 35, and , which concatenate to 143547.
Option 1 can be justified too. Here is a rule made up for this article, not from the slides: . gives , matching the data; gives . 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 , 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
(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 outside 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.
| Bin | Sample | |
|---|---|---|
| Orange | probability | fraction |
| Green | probability | fraction |
| Known or not | unknown | known |
The sample is 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: is the in-sample quantity and the out-of-sample quantity. The question is whether says anything about .
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 is likely close to the unknown .
"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 ; 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 ( large), is probably within of :
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 differs from the true probability by more than .
- is the error you are willing to tolerate.
- The right side is an upper bound on that probability, with in the exponent and a minus sign in front. Doubling squares the exponential term (), so the bound falls fast.
As an addition in this article, one point that is easy to misread: the random quantity is . is a property of the bin, a fixed but unknown number; every handful may give a different . The probability 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 "" 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:
- Valid for all and . does not have to pass some threshold before you can use it.
- The right side has no . So there is no need to know . Lin stresses in the lecture that this is why it can be used for inference: we never knew in the first place, and the formula assumes nothing about either.
- A larger , or a looser tolerance , gives a higher probability for "". 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 is large, we can probably infer the unknown by the known .
The numbers below were computed for this article. First the bound itself, plugging and into :
| 10 | 0.331 | 1.64 | 1.90 |
| 100 | 0.271 | 1.21 | |
| 1,000 | less than | 0.0135 | |
| 10,000 | smaller still | less than |
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 and 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, appears squared. To halve the error requirement, has to become four times as large for the bound to stay the same; to cut it to one tenth, has to be a hundred times as large: with and with both give a bound of 0.271.
Next, is it really only an upper bound? Take and and compute the probability of the bad event exactly from the binomial distribution:
| Exact | Hoeffding bound | |
|---|---|---|
| 10 | 0.334 | 1.64 |
| 100 | 0.0315 | 0.271 |
| 1,000 |
The exact values all sit below the bound, and by a wide margin. Computing the exact value needs and computing the bound does not; that is the trade between the two: Hoeffding is loose, but you can compute it without knowing .
Finally, use the formula in reverse. To have "the probability that the error exceeds is at most ", require the right side . Dividing both sides by 2 and taking the natural logarithm gives , and multiplying through by flips the inequality:
With and this gives , so 185 marbles are enough. Tightening the error to with the same requires , 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 . Use Hoeffding's Inequality
to bound the probability that a sample of 10 marbles will have . What bound do you get?
- 0.67
- 0.40
- 0.33
- 0.05
Answer: 3. The handout's solution is to set and : means is at least 0.3 below .
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: means at most 1 orange among the 10 marbles,
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 itself and has nothing to do with the probability being asked for. Option 1, 0.67, numerically equals , that is, 1 minus the bound; that number is a lower bound on the probability that and differ by at most 0.3, whereas the question asks for an upper bound on the probability that , 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 ", and at the gap is exactly 0.3. To be rigorous, take any slightly smaller than 0.3; then falls inside and the bound is ; as approaches 0.3 the bound approaches 0.331, and the answer does not change. Second, Hoeffding covers both sides: too low and too high both count. The probability that 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 ; Hoeffding holds for any , so it overestimates and is only an upper limit.
Replace marbles with data: one fixed hypothesis can be verified
(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:
| Bin | Learning |
|---|---|
| unknown orange probability | the probability that a fixed hypothesis differs from the target |
| a marble in the bin | an in the input space |
| orange | is wrong on this : |
| green | is right on this : |
| a size- sample of i.i.d. marbles from the bin | check on with i.i.d. , where |
In the lecture, Lin explains how this correspondence comes about. The unknown is , and estimating at every point of is too hard, so ask an easier question first: given a hypothesis in hand and a new customer, does what says differ from what says? Then treat every as a marble, painted orange where and disagree and green where they agree.
This painting has one precondition, which Lin states with emphasis in the lecture: you must have an in hand first, and it must be fixed; you cannot paint with this now and switch to another in a moment. Once painted, the bin belongs to this alone.
We cannot see the marbles' colors (that would require knowing ), but we can see the handful we drew. The data contain both and ; Lin adds a condition in the lecture: without noise, is simply . Comparing with tells us whether the -th marble is orange or green. The handout's conclusion: if is large and the are i.i.d., we can probably infer the unknown probability of by the known fraction of .
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 on . Dashed lines connect it to two places:
- To the training examples, meaning are drawn from .
- To the judgment "is ?", meaning the used to measure how good is also comes from the same .
Two solid lines also run to the judgment "is ?": one from the training examples and one from , labeled fixed . What is being judged is one fixed hypothesis borrowed from , 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 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 in place, the two quantities can be defined formally. In the handout's notation:
is this course's Boolean bracket: 1 if the statement inside holds and 0 if it does not. is the expectation. So is the probability that is wrong on an drawn from ; it corresponds to and is unknown. is the fraction of the examples on which is wrong; it corresponds to 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 is an expectation over all of , so an input that already appeared in still counts if it is drawn again. That is a different quantity from "counting only the inputs outside ": 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 , 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 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 according to the definition.
The guarantee for one hypothesis
In the lecture, Lin says what follows is only a substitution of words. Replace in Hoeffding with and with , and you have The Formal Guarantee of page 15. For any fixed :
The properties the handout lists match the bin page one for one:
- Valid for all and .
- The right side does not depend on , so there is no need to know ; and can stay unknown.
- "" is PAC.
On the second point, Lin explains in the lecture that we only assume and exist and do not actually need to know them; if we knew 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:
"With respect to " cannot be dropped. In the lecture, Lin says this is not an arbitrary guarantee: the data have to keep coming from the same for and 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" ()? In the lecture, Lin first reminds us that what the algorithm finally hands over is called , and is only one candidate in . The handout's answer has two sides:
| Condition | Conclusion | |
|---|---|---|
| Yes | is small for the fixed , and picks it as | "" is PAC |
| No | is forced to pick THE as | is almost always not small, so "" is PAC |
The cell on the right is the point. The derivation so far concerns one fixed in advance from start to finish. For the guarantee to hold, the algorithm would have to hand over the same no matter what the data look like. In the lecture, Lin explains that an algorithm returning the same whatever problem it meets will, nine times out of ten, return a poor with a large . Hoeffding still holds then, and and are still close; the conclusion you get is just that you can say with great confidence that is nothing like .
The handout's closing remark: real learning is making choices in (like PLA) rather than being forced to pick one . 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:
| Position | Learning flow | Verification flow |
|---|---|---|
| Data | training examples | verifying examples |
| Candidates | hypothesis set | one hypothesis |
| Algorithm | present, does the choosing | absent, simply |
| Output | the "learned" formula | a 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. , and is the uniform distribution giving each of the 8 inputs probability . The true target is from the table. The hypothesis is fixed in advance: on the first five inputs it gives the same answers as in the table, and on 101, 110, 111 it answers ○×○ (the of the student in the lecture).
Computing . is ×○× on 101, 110, 111, so is wrong on all three and right on the other five. . In the real world this number cannot be seen; here we can compute it only because we built the whole world ourselves.
Sampling. Draw inputs independently from (repeats allowed); each lands where is wrong with probability . The number of errors follows a binomial distribution, and :
| Probability | Exceeds ? | |||
|---|---|---|---|---|
| 0 | 0 | 0.375 | Yes | |
| 1 | 0.2 | 0.175 | No | |
| 2 | 0.4 | 0.025 | No | |
| 3 | 0.6 | 0.225 | No | |
| 4 | 0.8 | 0.425 | Yes | |
| 5 | 1 | 0.625 | Yes |
Result. With , the probability of the bad event is (exactly ). The Hoeffding bound is . The exact value is below the bound.
What this means. First, is too small and a bound of 0.813 carries almost no information; Hoeffding needs a large to be useful. Second, the handout's belongs to the row: all five examples fall where is right, looks perfect, and in fact . For an fixed in advance, such a misleading sample turns up with a probability of only about 9.5%. But the 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?
- You'll definitely be rich by exploiting the rule in the next 100 days.
- You'll likely be rich by exploiting the rule in the next 100 days, if the market behaves similarly to the last 10 years.
- You'll likely be rich by exploiting the "best rule" from 20 more friends in the next 100 days.
- 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 (she stated it before you picked the days); the bin is every day of the past 10 years, and is the uniform distribution over those days; the 100 days are a sample with ; 80 days satisfy the rule, so . Treating the 100 days as drawn independently and taking :
So with at least 97.8% confidence, the rule's error rate over the 10 years is no more than , 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 . That is exactly the final "with respect to " 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 , 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 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
(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 bins, one per hypothesis: the orange fraction in the bin of is , the orange fraction in its sample is , and so on down the row to . In the figure, the 10 marbles drawn from the bin of 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 "", is "" really magical?
A: No. Even if all coins are fair, the probability that one of the 150 coins results in 5 heads is
Derivation: a fair coin flipped 5 times comes up all heads with probability , so the probability of "not" all heads is . The 150 coins are independent, so the probability that none of the 150 is all heads is . 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 , 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 . All heads is . Picking out the all-heads coin amounts to picking the hypothesis with the smallest , and its is still . 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 ; with 150 to choose from, the probability exceeds 99%. In the handout's words: BAD sample means and far away, and it can get worse when involving "choice".
BAD sample and BAD data
Page 21 defines "bad" precisely:
- BAD sample: e.g., , but getting all heads ().
- BAD data for one : and far away. The typical case the handout gives is big (far from ) but small (correct on most examples).
In the lecture, Lin supplies the standard for "far": differing by more than .
The handout then draws a one-row table. Line up all the data sets that could possibly be drawn, , each one examples. For a fixed , each cell either is BAD or is not. In the handout's figure, the row of is BAD at and . The probability of BAD is a sum over all possible data sets:
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:
| … | … | Hoeffding | |||||
|---|---|---|---|---|---|---|---|
| BAD | BAD | ||||||
| BAD | |||||||
| BAD | BAD | BAD | |||||
| … | |||||||
| BAD | BAD | ||||||
| all | BAD | BAD | BAD | ? |
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:
In other words, one BAD cell anywhere in a column makes that data set BAD for the whole of . 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 and chooses it, and its turns out to be large. Lin reads off the table in the lecture: with , the mines you might step on are , , and ; with , the mines are and ; only something like , 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 hypotheses, what is the bound of ?
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
Line two: split the "or" into a sum. This step is called the union bound:
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: , where the last term is never negative, and dropping it gives . 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 is a fixed hypothesis that was sitting in before the data were drawn, so "the guarantee for one hypothesis" holds for it:
Line four: add up identical numbers.
The handout calls it the finite-bin version of Hoeffding and lists three points:
- Valid for all , , and .
- No need to know any ; and can stay unknown.
- "" is PAC, regardless of .
The third point is where the whole lecture lands. The handout states only the conclusion; this article fills in the reason. The the algorithm hands over is one of , and which one depends on the data. If this is not BAD, then every has and within of each other, so whichever one the algorithm picks, is within too. Put the other way round, " and of differ by more than " can only happen on a BAD :
Where "Verification is not learning" got stuck was that 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 is safe the algorithm can choose any way it likes. The price is an extra 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 (like PLA or pocket) picks the one with the lowest as . Lin's reason in the lecture: every hypothesis has and close together, so the one with the smallest will have an 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 can be computed. In a learning problem the 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 , 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. , :
| One rule: | One picked out of 21: | |
|---|---|---|
| 0.10 | 0.271 | 5.68 |
| 0.15 | 0.022 | 0.467 |
| 0.20 | 0.00067 | 0.0141 |
When only one rule is verified, already gives 97.8% confidence. After choosing, the same leaves only 53.3% confidence; to get back to roughly the same confidence level, 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 and rearrange as before:
sits inside the logarithm. With and : needs 185 examples, needs 415, and 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 , with . With the bound is , 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 on every drawn input and disagrees on every undrawn one, with and . So every possible is BAD, and .
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 is too large and too small, so the union bound exceeds 1. Conversely, if the candidates are restricted in advance to 2 hypotheses and there are independently drawn examples, the same gives . 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 .
The condition for feasibility, and what remains unsolved
Page 24 writes the conclusion as The 'Statistical' Learning Flow:
- If is finite and is large enough, then for whatever picked by , .
- If finds one with , there is a PAC guarantee for , 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 : one generates of the training examples, and one generates the used to test .
The lower right of the diagram leaves a question: what about (like perceptrons)? There are infinitely many lines in the plane, and becomes infinite outright. In the lecture, Lin voices the students' objection for them: after all this, 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:
- Learning is Impossible?: absolutely no free lunch outside .
- Probability to the Rescue: probably approximately correct outside .
- Connection to Learning: verification possible if small for fixed .
- Connection to Real Learning: learning possible if finite and small.
Fun Time: BAD data of four hypotheses
Question (page 25): Consider 4 hypotheses:
For any and , which of the following statements is "not" true?
- the BAD data of and the BAD data of are exactly the same
- the BAD data of and the BAD data of are exactly the same
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 case.
Why option 2 is true. , so the two give opposite answers at every point. Where is right is wrong and vice versa, so
Subtracting gives , with the same absolute value. A data set that is BAD for is BAD for as well. This is Lin's explanation in the lecture: multiply a hypothesis by a minus sign and both and flip relative to it, so they stay equally far apart. (At points where is exactly 0 both are ; that case is not discussed here.)
Option 3 is true. It is just plugged into .
Option 4 is true as well. By the same argument and have the same BAD data. The four events are really only two distinct events, the first line of the derivation becomes "BAD for or BAD for ", and the union bound needs only two terms: .
Why option 1 is not true. looks at the first coordinate and 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. is the uniform distribution on the four points , , , , and is on the first three points and on . Then is wrong only at , is wrong only at , and both have equal to . Take and , drawing two points in order for 16 equally likely data sets. can only be 0, , or 1. For and , the only value more than 0.3 away from is , which means both draws hit the point where the hypothesis is wrong. and have equal to , and the only value more than 0.3 away is , which means both draws hit the single point where the hypothesis is right: for that point is , and for it is .
| Hypothesis | BAD data sets | Probability |
|---|---|---|
| both draws are | ||
| both draws are | ||
| both draws are | ||
| both draws are |
The BAD data of and of are two different data sets, so option 1 is not true; those of and are the same data set, so option 2 is true. The probability that at least one hypothesis goes wrong is , while adding the four rows directly gives ; the excess is exactly the overlap counted twice. The 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 on independently drawn examples. With , what is the Hoeffding bound? If this hypothesis was the one with the lowest 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 ?
Answer: for one hypothesis, , so with 83.6% confidence lies between 0.03 and 0.13. With 20 candidates, multiply by 20 to get 3.28, which exceeds 1 and guarantees nothing. , so 1,337 examples are needed.
2. Explain in your own words: why can Hoeffding's inequality not be applied directly to the that PLA finds?
Criteria: the answer should mention three things. First, painting marbles orange or green requires a fixed beforehand, and the bin belongs to that alone. Second, is decided after looking at the data, and a different data set gives a different , so it is not a hypothesis fixed in advance. Third, the remedy is to require every candidate in to be safe at once, paying a factor of through the union bound. Answering only "because 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 . The probability that at least one person gets all heads is . The union bound gives . 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. , and the data give the answers for 10 distinct inputs, without noise. How many target functions are fully consistent with ? For some that is correct on all of , how many of the inputs outside does it get right on average (averaging over all consistent target functions)?
Answer: has inputs, 6 remain outside , and each has 2 possible answers, so there are consistent target functions. For each unseen input, exactly half of the 64 functions say ○ and half say ×, so whatever guesses it matches only half of them, and on average it gets right, the same as random guessing.
5. A hypothesis set has 100 hypotheses that form exactly 50 pairs of " and ". Can the bound on be written smaller than ?
Answer: yes. and 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 . 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 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 hypotheses as bins sharing the same 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 , reach with a perceptron, and ask for the smallest and largest error rate outside . This is a direct drill on the No Free Lunch table.
- Q7: estimate by Monte Carlo dart throwing; how many darts are needed for the probability that the error is within to exceed 0.999? The method is to solve Hoeffding in reverse for .
- Q8–9: compute of two hypotheses on , then the probability that their 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 terms come from some polynomial of degree , 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: 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 . 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 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
- Foundations Lecture 4 handout 04_handout.pdf: the main source for this article; the content of the four sections, the tables, the four Fun Time questions, and all formulas come from this handout.
- Machine Learning Foundations YouTube playlist: the IDs and titles of the four videos; what the text reports as said "in the lecture" is paraphrased from machine transcripts of these four videos.
- Hsuan-Tien Lin > MOOCs: the official portal for handouts and recordings.
- Machine Learning, Fall 2026 course page: the W3 required pre-class viewing list, the LFD section, and further reading.
- Fall 2026 extended slides 04e_handout.pdf: the example with the sequence 1, 4, 1, 5, the one-sentence version of the No Free Lunch theorem, and the explanation of dependent sampling.
- Fall 2026 Homework 1 (hw1.pdf): the content of Q6–10.
- Fall 2024 Homework 2 (hw2_red.pdf): the content of Q2 and Q5–8.
- Wolpert (1996), The Lack of A Priori Distinctions Between Learning Algorithms: the No Free Lunch further reading listed on the course pages.
- Learning from Data textbook site: the source for LFD 1.3.
- Caltech Learning from Data telecourse: further reading; Lecture 2: Is Learning Feasible? corresponds to this lecture.
- Stanford CS229 guide: further reading, an article on this site.
- Reading NTU Hsuan-Tien Lin Machine Learning Foundations & Techniques: Course Overview: where this lecture sits in the whole course, and the reading routes.