🌏 中文版
Video status: Videos included. This article is written from the official MOOC handout 208_handout.pdf and transcripts of the four official videos for this lecture, 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/25 to 25/25), and wherever the text says "in the lecture" it is paraphrasing what is said in the video.
This is Techniques Lecture 8 in Reading NTU Hsuan-Tien Lin Machine Learning Foundations & Techniques. The Roadmap on page 1 of the handout divides Techniques into three ways of handling features, and this lecture belongs to the second, Combining Predictive Features: Aggregation Models. The previous lecture, Techniques Lecture 7: Blending and Bagging, is condensed into one sentence on that page: when you already hold a set of diverse hypotheses, you can combine them uniformly, linearly, or even non-linearly (blending); when you do not, you can learn diverse hypotheses from bootstrapped data (bagging).
Bagging's diversity depends on the luck of sampling. This lecture asks: can we design each round's data on purpose, so that the newly learned hypothesis is certain to differ from the previous one, and so that the final combined comes with a theoretical guarantee? The answer is Adaptive Boosting, AdaBoost for short.
The prerequisites are bootstrap and linear blending from the previous lecture, weighted classification from Foundations Lecture 8: Noise and Error Measures, the form of the VC bound, and basic arithmetic with logarithms and square roots. After reading, you should be able to derive on your own the pair of multipliers "what to multiply the incorrect ones by, what to multiply the correct ones by", write down the three steps of AdaBoost, compute each round's , , , and new weights by hand for a small data set, and explain why "a little better than random guessing" is enough.
The order of the derivation in this lecture:
- Motivation: many crude rules, plus a teacher who points out mistakes, can be combined into a good classifier.
- Bootstrap as weights: every in bagging is in fact minimizing a weighted error.
- Designing the weights: make look like a coin flip under the next round's weights, which gives the optimal re-weighting.
- The scaling factor : write the re-weighting as "multiply the incorrect, divide the correct".
- The vote weight : decide the weights of the linear vote while learning each .
- Guarantee and practice: both terms of the VC bound can be made small; then run it with decision stumps.
Can weak rules be combined into a strong one: a class on recognizing apples
(Video 00:17–01:14 reviews the previous lecture, 01:14–02:22 introduces the topic, 02:22–10:30 is the classroom story, 10:30–12:23 maps the roles back to the algorithm, and Fun Time follows.)
Twenty photos
Page 2 of the handout sets up a problem: teach a class of 6 year olds to tell whether a photo shows an apple. The teacher gathers photos under the CC-BY-2.0 license from Flickr, ten of apples and ten of other things. The non-apples named in the lecture are bananas, oranges, and strawberries, and tomatoes show up later in the story.
Lin first maps this setting back to machine learning vocabulary: the twenty photos are , whether each is an apple is , the teacher gives the students both, so this is supervised learning, and what is to be learned is a binary classification.
Four students, one teacher
Pages 3 to 6 of the handout are four rounds of question and answer, with the twenty photos at the bottom of every page. Pages 3 to 5 mark with a blue background the photos that this round's rule gets wrong; from page 4 on, the size of each photo changes with the previous round's result, with the ones answered wrongly enlarged and the ones answered correctly shrunk. The table below collects the four pages:
| Round (handout page) | The rule the student gives | Where the rule goes wrong (as explained in the lecture) | The class's conclusion so far (handout) |
|---|---|---|---|
| 1 (page 3) | Michael: apples are circular | Oranges are circular too; one apple does not look that round in its photo | Apples are circular |
| 2 (page 4) | Tina: apples are red | Green apples are not red; strawberries and tomatoes are red but are not apples | Somewhat circular and somewhat red |
| 3 (page 5) | Joey: apples could also be green | Quite a few photos are wrong, but they all fall on photos that have already been shrunk | Somewhat circular and somewhat red and possibly green |
| 4 (page 6) | Jessica: apples have stems at the top | (The last round; the handout marks no more mistakes) | Somewhat circular, somewhat red, possibly green, and may have stems at the top |
What matters is what the teacher does between rounds. After Michael says "circular", the teacher does not simply reject it. The line on the handout is: being circular is a good feature for the apples, but if you only say circular you could make several mistakes, so what else can we say for an apple? Lin describes the teacher's action concretely: move the photos Michael got right farther away (drawn as shrinking on the slide), enlarge the photos he got wrong, and then ask the next student to look.
What Tina sees is not what Michael saw. As Lin describes it, the enlarged photos include two big red apples, while most of the other fruit that are not apples are not red, so she says "red". That rule was drawn out by those few enlarged photos.
Joey's round has a detail that is easy to miss. Lin says the rule "green" looks as if it gets a great many photos wrong, but all those mistakes happen on photos that are currently shrunk very small, which are not what Joey is concentrating on; on the photos he mainly sees (two green apples and one tomato enlarged a great deal), the rule makes sense. As for the mistakes it makes, the next round will fix them.
After four rounds, Lin's comment is that this conclusion may not be perfect yet, but it is richer than what each student could have said alone.
Mapping the roles back to the algorithm
Page 7 of the handout maps the three roles:
| In the story | In the algorithm | How the handout puts it |
|---|---|---|
| Students | Simple hypotheses | simple hypotheses, like vertical/horizontal lines |
| The class | The combined, complex hypothesis | sophisticated hypothesis, like the black curve in the figure |
| Teacher | A learning algorithm that guides the students | directs the students to focus on key examples |
The figure on the same page is a 2D example: several circles and crosses, a few gray vertical and horizontal lines in the background, and a black piecewise boundary that separates the circles from the crosses completely. Lin says that being allowed to cut only vertical and horizontal lines, with not even a slanted line permitted, is a very weak way to classify, just like those schoolchildren; the black boundary is the result of combining these lines, and it is richer than every one of them. This figure is redrawn round by round where the AdaBoost-Stump demonstration is covered.
Lin defines "key examples" as the examples on which mistakes were made: emphasizing them is what makes the next student find a different line. The rest of the lecture answers the math of this: how much to enlarge, how much to shrink, and how to combine at the end.
Fun Time: which one helps recognize an apple
Question (page 8): Which of the following can help recognize an apple?
- apples are often circular
- apples are often red or green
- apples often have stems at the top
- all of the above
Answer: 4. The handout's solution is one sentence congratulating you on passing first grade. The point of the question is in the wording of the choices: each one says only "often", and using a single one of them alone to classify would make mistakes (in the story, the teacher pointed out mistakes for each of the first three students), yet each one is more useful than random guessing. Choosing 1, 2, or 3 alone leaves out two other rules that are just as useful. "Each one weak, but each better than random guessing" is exactly the only requirement placed on the base algorithm later.
How to force a different hypothesis: see bootstrap as weights, then design the weights yourself
(Video 00:00–03:03 rewrites bootstrap as weights, 03:03–06:29 discusses how a base algorithm takes weights, 06:29–09:19 is the idea of "making the previous hypothesis look like a coin flip", 09:19–13:35 derives the optimal re-weighting, and Fun Time follows.)
Bagging is in fact minimizing a weighted error
Page 9 of the handout starts from the previous lecture's bagging. Suppose the original data has four examples, and bootstrap draws example 1 twice, example 2 once, example 4 once, and never draws example 3:
The base algorithm minimizes the 0/1 error on :
Lin's observation is this: since the two copies of example 1 are identical, we may as well keep the original four examples and use a separate variable to record "how many copies" each one has. Here , , , , and the same thing can be written as a weighted error on the original data :
The spoken version in the lecture: getting an example with two copies wrong costs two points, and one with a single copy costs one point. The superscript stands for round , because each round's bootstrap draws a different set of .
This article checks one case: suppose some gets only example 1 wrong. In the bootstrapped-data form, two of the four examples in are wrong, an error rate of ; in the weighted form it is . The two forms give the same number.
The handout sums this page up in one sentence: each diverse in bagging is obtained by minimizing the bootstrap-weighted error. The use of this rephrasing is that the weights do not have to be decided by sampling.
The base algorithm has to take weights
Page 10 of the handout writes the weighted error in general form. What is minimized (a regularization term may be added) is
Lin says the weights are integers in bagging, but there is no reason they must be integers: give 10 to an example that is ten times as important, and 0.8 to one that is 0.8 times as important. Lin then asks a question on the students' behalf: earlier algorithms only had to do well on , so what do we do now that there is a ? The handout gives two examples to show that this is usually not hard.
SVM. In soft-margin SVM, the cost of each example's margin violation was multiplied by ; now the cost of example is multiplied by . The handout's conclusion is that when solving by dual QP, this amounts to changing the upper bound on from to :
Lin's explanation is: one mistake used to cost points, and with two copies it now costs points; after going through the whole QP derivation, this parameter ends up in the upper limit on . This article fills in the step in between (using the derivation in Techniques Lecture 4: Soft-Margin SVM): the weighted primal problem minimizes . The term containing in the Lagrange function is , where is the multiplier of the constraint . Setting the partial derivative with respect to to 0 gives , and then gives . The rest of the dual problem is completely unchanged.
Logistic regression. When training with SGD, each step used to pick one example uniformly at random to compute the gradient. The handout's approach is to sample in proportion to instead. The reason given in the lecture: if an example has 10 copies, its chance of being drawn ought to be 10 times everyone else's in the first place. This article adds one line of math: when example is drawn with probability , the expected gradient is , which is proportional to , the gradient direction of the weighted error.
At the bottom of the page the handout notes that this kind of learning, where each example carries its own weight (example-weighted learning), is an extension of class-weighted learning in Lecture 8 of ML Foundations. Lin looks back: Foundations Lecture 8 was about which of two kinds of mistake is more serious in fingerprint verification, and the weight followed the class; now the weight follows each individual example. Lin says most of what was learned in that lecture carries over (a note from this article: the approach in that lecture was to think of a high-cost example as copied many times).
From here on, the derivation assumes that the base algorithm accepts weights: give it data and weights , and it returns a hypothesis whose weighted error is as small as it can make it.
Making the previous hypothesis look like a coin flip under the new weights
Page 11 of the handout returns to binary classification and asks how to design the weights to get more diverse hypotheses. The previous lecture concluded that the more the hypotheses differ, the better the combination works. Hypotheses in two neighboring rounds come about like this:
is the hypothesis with the smallest weighted error under . The handout's reasoning: if is "not good" for , then and the hypotheses that look like will not be returned as , so will be diverse from . Lin puts it this way: is already in hand, so just adjust the weights a little to make it perform badly in the new round, and none of the hypotheses much like it will be picked.
What is the standard for "performing badly" in binary classification? Lin's answer is being no different from flipping a coin. The expected error rate of a coin flip is , so the handout writes the goal as: construct so that the weighted error rate of is exactly one half.
The denominator is the total of all the weights; dividing by it converts the weighted error into a proportion.
An addition in this article: why is the target , instead of pushing the weighted error rate of higher, to for example? In binary classification, a weighted error rate of for means a weighted error rate of for . If the hypothesis set contains both and (decision stumps do, since the direction can be positive or negative), the base algorithm would simply pick in the next round, which is just the same line used the other way around and brings no new information. is the only position where both and are useless, so the algorithm has to go and find some other hypothesis.
Optimal re-weighting: the handout's 1126 and 6211
Page 12 of the handout splits that ratio into two pieces. Write for the total, under the new weights, of the examples gets wrong, and for the total of the ones it gets right (read aloud in the lecture as the square and the circle):
Every example is either wrong or right, so the total of all the weights is , and the goal becomes
Why the two are equivalent: cross-multiplying the left side gives , and moving a term over gives the right side. So there is only one thing to do: make the total weight of the incorrect group equal to the total weight of the correct group.
Lin says there are many ways to achieve this, and the handout picks the one that matches enlarging and shrinking photos in the story: multiply each group by its own number. The handout demonstrates with a set of numbers. Suppose that under the current weights the incorrect total is 1126 and the correct total is 6211:
| The incorrect group | The correct group | |
|---|---|---|
| Current total weight | ||
| Share of the whole () | ||
| The handout's approach: multiply each example by | ||
| New total weight |
Each side is multiplied by the other side's total, so of course the new totals are equal, both (checked for this article). Dividing both by works the same way: multiply each incorrect example by (the correct rate) and each correct example by (the incorrect rate), and both sides become .
Now replace the numbers with symbols. Let the weighted error rate of under the current weights be
and let . The incorrect group totals and the correct group totals . After multiplying each incorrect example by and each correct example by :
The handout calls this conclusion 'optimal' re-weighting:
Multiply the incorrect ones by something proportional to , and the correct ones by something proportional to .
"Proportional to" means the two multipliers can both be multiplied by the same positive constant, because the two totals then grow together and stay equal. The only thing really determined is the ratio of the two multipliers, . In the handout's example , and this ratio is : relative to each correct example, the importance of each incorrect example is raised to 5.52 times what it was.
Lin wraps up here: once the two sides are made equal, the original performs badly in the new round and should not be picked by the base algorithm again.
Fun Time: four examples, one wrong
Question (page 13): Four examples, each with . predicts the first example wrongly but all the other three examples correctly. After the 'optimal' re-weighting, what is ?
Answer: 2. The weights are all equal, so . Example 1 is wrong and is multiplied by something proportional to ; example 2 is right and is multiplied by something proportional to . The two started with the same weight, so the ratio is . In the handout's words, example 1 is now three times more important than every other example.
Check that the goal is met: the new weights are proportional to , the incorrect group totals 3, the correct group totals , and the weighted error rate of is .
The other choices: is , which amounts to remembering only that correct examples are multiplied by while letting the incorrect one be multiplied by 1; the multiplier for incorrect examples is , and the right ratio is . has the numerator and denominator swapped, which is ; and is itself. A quick check: an incorrect example should get heavier, so the answer must be greater than 1, and the last two choices can be ruled out directly.
The AdaBoost algorithm: scaling factor, vote weights, and theoretical guarantee
(Video 00:00–02:24 is the scaling factor, 02:24–04:58 is the preliminary algorithm and its two gaps, 04:58–08:00 decides the vote weights, 08:00–10:01 is the full algorithm, 10:01–13:07 is the theoretical guarantee, and Fun Time follows.)
The scaling factor ◆: multiply the incorrect, divide the correct
The conclusion of optimal re-weighting is two multipliers: multiply the incorrect by and the correct by , with the freedom to multiply both by a constant. Page 14 of the handout picks a constant that makes the formulas symmetric and defines the scaling factor
and then writes the update rule as
The handout says this is equivalent to optimal re-weighting. The derivation is as follows. Divide both of the original multipliers by :
The ratio of the two multipliers is still , and Lin also uses this ratio to explain that the two forms have the same effect. A direct check works too: the new total of the incorrect group is and that of the correct group is , and the two are equal.
The benefit of switching to is that it has a direct physical meaning. The handout writes if and only if :
Lin adds that is usually smaller than , because is the level of random guessing and there is an algorithm underneath doing the learning, which ought to learn better than random guessing. In that case , "multiplying by " really enlarges and "dividing by " really shrinks, which is what the handout writes as scale up incorrect, scale down correct, the same thing the teacher does in the story. Lin also compares it with the PLA of Foundations Lecture 2: conceptually a bit alike, in that a mistake prompts a correction.
The handout's example corresponds to (computed for this article): multiply each incorrect example by 2.349 and divide each correct example by 2.349.
Two pieces still missing: the first round's weights, and how to combine at the end
Page 15 of the handout writes what we have so far as a preliminary algorithm, leaving two question marks:
- For : obtain by , where tries to minimize the -weighted 0/1 error; then update to by .
- Return
The first round's weights. The handout's answer is that we want to be 'best' for the original , so . When every example has the same weight, the weighted error is the ordinary .
How to combine at the end. The most intuitive choice is a uniform vote, as in bagging. Next to this option the handout writes "but very bad for ", with a "why? :-)" attached. Lin's explanation: is chosen under uniform weights and is good for ; is chosen under weights deliberately made to defeat , is very different from , and is probably not good for the original . Giving a good one and a poor one the same vote may not turn out well.
An addition in this article: "very bad" is a tendency, not a theorem. The only statement this lecture can strictly guarantee is the weighted one: the error rate of under is . In the numerical example later, the error rate of on the original data is , the same as that of .
The handout goes on to say that combining linearly or non-linearly is up to you (as you wish). Lin's point in the lecture is that once you hold a pile of , every kind of blending from the previous lecture can be applied again. But this lecture introduces a special approach: decide the coefficients of the linear combination along the way, while learning the . The handout calls it linear aggregation on the fly, and it comes with a theoretical guarantee.
Deciding the vote weights while learning
Page 16 of the handout adds a third step inside the loop:
Lin explains "on the fly": each time a is decided an is decided too, so both are available when the algorithm finishes, and there is no need to go back and solve a linear blending problem.
The design requirement for is that a good gets more votes. Lin's reasoning: a good has a small , a small means a large , so letting be some monotonically increasing function of meets the requirement. The handout writes and then takes the natural logarithm directly. Lin says only that this is a particular choice made by the people who designed the algorithm, and does not explain in this lecture why it is a logarithm; the handout calls it 'magic' linear aggregation. The reason does not appear until Techniques Lecture 11: Gradient Boosted Decision Trees looks at AdaBoost again from the optimization side.
The handout checks two extremes:
- : , . As Lin puts it, a as bad as a coin flip gets no votes at all, which amounts to keeping it out of .
- : , . brings the weighted error to 0 all by itself, so it gets infinitely many votes and listens to it entirely.
For the cases in between, this article lists a few numbers (all computed with and checked in Python):
When the error rate drops from to , the vote weight becomes more than five times what it was; a only slightly better than random guessing () has almost no say.
The same page breaks AdaBoost into three components and maps each back to a role in the story:
| Component | Role | What it does |
|---|---|---|
| Weak base learning algorithm | Student | Looks at the weights the teacher has prepared and picks this round's best |
| Optimal re-weighting factor | Teacher | Enlarges the incorrect, shrinks the correct |
| 'Magic' linear aggregation | Class | Combines the into , each weighted by how well it did |
The full algorithm
Page 17 of the handout is the full version:
- Initialize .
- For :
- Obtain by , where tries to minimize the -weighted 0/1 error.
- Compute and , and update to : for incorrect examples , for correct examples .
- Compute .
- Return .
where
This article adds two details you run into when implementing it. First, the weights do not need to be normalized to sum to 1: is a ratio, so multiplying all by the same constant leaves , , , and "which hypothesis has the smallest weighted error" unchanged. The hand computation later uses this to write the weights as integer ratios. Second, if in some round, divides by 0 and the program has to handle that case separately; here classifies the weighted data perfectly all by itself, and by the handout's account it should get infinitely many votes.
Lin mentions in the lecture that AdaBoost has a Chinese name meaning roughly "the cobblers' method", after a proverb that three cobblers together outdo one Zhuge Liang, a famous strategist; the summary on the last page of the handout uses the English saying two heads are better than one. The property of making weak strong is called boosting, and at the bottom of this page the handout writes that AdaBoost has a provable boosting property.
Theoretical guarantee: both terms can be made small
Page 18 of the handout applies the VC bound from Foundations to :
The first term on the right is how does on the training data, and the second is the price of model complexity. Lin explains where the second term comes from: is the complexity of the hypothesis set that a single lives in, and when of them are combined, the overall VC dimension can be proved to be roughly times that; the rest is the standard form of the VC bound. Lin says explicitly that the detailed proof is not done here.
The handout draws one conclusion for each term:
- The first term can be small. If always holds, then after iterations. Lin says this is a result proved by the original authors.
- The second term can be small. The overall grows "slowly" with . As Lin puts it, only needs to be about , so once the amount of data is large enough the whole second term is small too.
With both terms small, is small. The handout calls this conclusion the boosting view of AdaBoost:
If is weak but always slightly better than random (), then (AdaBoost + ) can be strong ( and small).
Lin's way of saying it: we ask only a little of the algorithm underneath, namely being slightly better than random guessing, and AdaBoost can make it stronger and stronger, strong enough that is 0 and is guaranteed as well.
An addition in this article: note that the in the condition is a fixed number smaller than , and no round's may exceed it. is measured under weights that get trickier and trickier, so this condition is not an easy one: it requires the base algorithm to come up with a hypothesis better than random guessing no matter what weights it faces.
An addition in this article: where the O(log N) iterations come from
What follows is not on this lecture's handout and is not done in the lecture either. It is written here to give the phrase "" on page 18 of the handout a source. The whole argument rests on three facts. The first is a proof problem in the Fall 2024 homework (see the exercises at the end), so only the conclusion and the intuition are given here and the proof is left to you; this article works through the other two.
Fact one (conclusion only): the total weight is multiplied by a number smaller than 1 in every round. Let . After each round's update,
When , , so the total weight keeps shrinking. This factor depends only on : the better is (the smaller ), the faster it shrinks, and the closer is to , the closer the factor is to 1. You can check the numbers against the six-fruit-photo example later: the three rounds' are , the factors are , and the total weight goes .
Fact two: each example's final weight records the votes it received. and are both ; when the prediction is right , and when it is wrong the product is . So "multiply the incorrect by , divide the correct by " can be written as a single formula:
The second equality uses . Starting from and multiplying through rounds:
The sum in the exponent is exactly the score of before taking the sign. Here the choice of the logarithm shows a little of its purpose: it ties the weights directly to the voting score. The handout of Techniques Lecture 11 writes down the same formula and looks at AdaBoost again starting from it.
Fact three: the total weight bounds . If misclassifies example , and the score have opposite signs (or the score is 0), the quantity in the exponent is greater than or equal to 0, and so . Every example misclassified by contributes at least , so
Putting it together. ; now multiply the conclusion of fact one through rounds. The function is increasing on , so means every factor is at most :
Let , a constant smaller than 1. can only be an integer multiple of , so as soon as , can only be 0. Solving for :
The denominator is a constant that depends only on , so . For example, with we get , and needs , so 339 rounds guarantee . This is an upper bound meant as a guarantee; in practice it often happens much earlier.
Fun Time: when is α positive
Question (page 19): According to and , when would ?
Answer: 1. is positive when its argument is greater than 1, so . The handout's solution says the math part should be easy and the interesting part is the physical meaning: is useful for (its vote weight is positive) if and only if its weighted error rate is better than random.
The other choices: choice 2 has the direction reversed; when , and is negative. Choices 3 and 4 both include cases where is not positive; for example is neither 1 nor 0, yet .
An addition in this article: a negative does not mean is useless. A with has an error rate of when used the other way around, and the negative vote weight flips it in exactly that way. This is the same reasoning as in the previous lecture, where linear blending could drop the constraint . The only truly useless case is .
Running it for real: decision stumps, two demonstrations, and face detection
(Video 00:00–02:18 is the decision stump, 02:18–05:05 is the round-by-round demonstration on simple data, 05:05–06:35 is the complicated data, 06:35–08:47 is face detection, 08:47–09:14 is Fun Time, followed by the summary and a preview of the next lecture.)
A weak base algorithm: the decision stump
AdaBoost needs a weak base algorithm . The requirement on page 20 of the handout is that it minimizes the weighted error "a little bit". A popular choice is the decision stump, which the handout reminds you appeared in ML Foundations Homework 2:
It has three parameters: which feature to look at, where the threshold cuts, and the direction (whether the right side of the threshold is judged positive or negative). The handout calls it positive and negative rays on some feature. Lin's description: on each dimension it is like a perceptron that looks only at that dimension, cutting once so that one side is positive and the other negative. In the 2D plane it is the vertical or horizontal line in the figure on page 7 of the handout.
The handout says it is efficient to optimize, in time, where is the number of features. Lin's reasons come in two layers. First, on the data these three parameters really have only finitely many combinations, and searching through all of them finds the best one, so the decision stump is one of the few hypothesis sets for which can truly be minimized, and the same goes for the weighted version. Second, sorting the data on each feature first and being a little clever in the computation gets it down to ; Lin leaves the details to interested students.
This article fills in that clever part. For a single feature : sort the examples by , which costs . The threshold produces a different split only when it sits between two neighboring examples (or outside all the data), so there are at most candidate values of . Move from the far left to the right one slot at a time; each move switches just one example from the right of the threshold to the left, so the weighted error only needs that example's added or subtracted, which is . The weighted error for equals the total weight minus the weighted error for , so no separate scan is needed. Each feature therefore costs only after sorting, and features cost in total.
The handout's overall verdict on the decision stump: it allows efficient minimization of but is perhaps too weak to work by itself. Lin says it can only make vertical and horizontal cuts, which is not enough on its own most of the time; now that we have AdaBoost, being weak is fine. The combination of the two is called AdaBoost-Stump.
A numerical example: three rounds by hand on six fruit photos
What follows is an example made up for this article, not from the slides, and all the numbers were computed in Python (the program is at the end of this subsection). It continues the apple story but reduces each photo to one feature.
Data. Six photos, with feature a color level, 1 the greenest and 6 the reddest. Two green apples sit at the green end, two red apples at the red end, and a banana and an orange are in the middle:
| 1 | 2 | 3 | 4 | 5 | 6 | |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| Photo | green apple | green apple | banana | orange | red apple | red apple |
Candidate hypotheses. With a single feature, the decision stump is . Put the threshold at the six positions , each with two directions, for 12 different rules in total. Each rule can cut only once, and the right answer is "apples at both ends, not in the middle", so none of them gets everything right. The three below are the ones that actually get used; in these three rounds the other nine each have a higher weighted error rate than the rule chosen in that round:
| Label | Parameters | In plain words | Predictions ( to ) | Which examples it gets wrong |
|---|---|---|---|---|
| A | , | Everything is an apple | 3, 4 | |
| B | , | The greener ones are apples | 5, 6 | |
| C | , | The redder ones are apples | 1, 2 |
On a tie, the convention is to take the rule with the smaller .
Round 1. , the same weight for every example. A, B, and C each get two examples wrong, a weighted error rate of , the lowest among the 12. By the convention we take A: A.
Update: examples 3 and 4 are wrong and are multiplied by , becoming ; the other four are divided by , becoming . The ratio of the two is , so the new weights are proportional to . Check: the incorrect group totals , the correct group totals , and the error rate of A under the new weights is exactly .
Round 2. The weights are proportional to , with total 8.
- A gets 3 and 4 wrong: . The previous round's winner is now the same as a coin flip.
- B gets 5 and 6 wrong: .
- C gets 1 and 2 wrong: .
B and C tie, and we take B with the smaller : B.
Update: examples 5 and 6 are multiplied by and the rest divided by , so the ratio between the incorrect and correct multipliers is 3. The original becomes proportional to . Check: the examples B gets wrong total , and the ones it gets right total .
Round 3. The weights are proportional to , with total 12.
- A gets 3 and 4 wrong: .
- B gets 5 and 6 wrong: . This time it is B's turn to become a coin flip.
- C gets 1 and 2 wrong: .
C.
Combining. :
| Score | ||||||
|---|---|---|---|---|---|---|
| 1, 2 | ||||||
| 3, 4 | ||||||
| 5, 6 |
All six are right, . The exact values of the three scores are , , and .
The three rounds side by side:
| Weights after the update (proportional to) | Total weight after the update | of the first combined | |||||
|---|---|---|---|---|---|---|---|
| 1 | A | ||||||
| 2 | B | ||||||
| 3 | C |
What this result means.
- says "the very green or very red ones are apples", a rule that takes two cuts, which none of the 12 decision stumps can do. Three rules that are each wrong on a third of the data get everything right once combined, and that is boosting.
- The rule chosen in each round is certain to have a weighted error rate of exactly in the next round (A in round 2, B in round 3), so the base algorithm will not choose the same rule two rounds in a row. This is the design goal of optimal re-weighting, and it is directly visible in the numbers.
- getting smaller round after round () is just a coincidence of this data and does not happen in general; but all three rules have an error rate of on the original data and still get different vote weights, because the vote weight reflects performance under the weights at that time.
- A, "everything is an apple", looks like the emptiest rule, yet it cannot be left out. Without it, the score at is , which would be misclassified. Its role in the vote is like a constant term that pushes the overall score in the positive direction.
- The of the first two combined makes no progress (, so with only two, is just ), and it drops to 0 only in the third round. is not guaranteed to decrease in every round; what decreases all the way is the total weight, , multiplied by in each round, and it stays above throughout, consistent with the derivation added earlier.
- In this example a uniform vote among the three rules happens to get everything right too, so it does not show a case where "one vote each breaks down"; what it shows is how re-weighting forces out three different rules.
The program used for checking (pure Python):
from math import sqrt, log
X = [1, 2, 3, 4, 5, 6]
Y = [+1, +1, -1, -1, +1, +1]
N = len(X)
def stump(s, theta):
return lambda x: s * (1 if x > theta else -1)
# 6 thresholds, two directions each, 12 stumps in total; ties go to the earlier one
candidates = [(s, th) for th in [0.5, 1.5, 2.5, 3.5, 4.5, 5.5] for s in (+1, -1)]
u = [1 / N] * N
score = [0.0] * N
for t in range(1, 4):
def eps_of(c):
h = stump(*c)
return sum(un for un, x, y in zip(u, X, Y) if h(x) != y) / sum(u)
best = min(candidates, key=eps_of)
eps = eps_of(best)
dia = sqrt((1 - eps) / eps)
alpha = log(dia)
g = stump(*best)
u = [un * dia if g(x) != y else un / dia for un, x, y in zip(u, X, Y)]
score = [sc + alpha * g(x) for sc, x in zip(score, X)]
e_in = sum((1 if sc > 0 else -1) != y for sc, y in zip(score, Y)) / N
print(t, best, round(eps, 4), round(dia, 4), round(alpha, 4),
[round(un, 4) for un in u], round(sum(u), 4), round(e_in, 4))
The three output lines list, in order, the round, the chosen , , , , the six weights after the update, the total weight, and :
1 (1, 0.5) 0.3333 1.4142 0.3466 [0.1179, 0.1179, 0.2357, 0.2357, 0.1179, 0.1179] 0.9428 0.3333
2 (-1, 2.5) 0.25 1.7321 0.5493 [0.068, 0.068, 0.1361, 0.1361, 0.2041, 0.2041] 0.8165 0.3333
3 (1, 4.5) 0.1667 2.2361 0.8047 [0.1521, 0.1521, 0.0609, 0.0609, 0.0913, 0.0913] 0.6086 0.0
The handout's demonstration: five cuts on ten points
Page 21 of the handout plays AdaBoost-Stump round by round on a small 2D data set, in which you can count 5 circles and 5 crosses. In each picture, the size of a point stands for its weight after that round's update, the dashed line is the cut newly made in this round, and the thick black line is the current boundary of . In the first two pictures the black line lies on top of the new cut, and only from the picture on can you see it turn. The table below is compiled from the slide's pictures and the explanation in the lecture; the directions and the misclassified points in the and rows were read off the pictures for this article:
| Picture | This cut | Which points this cut gets wrong (enlarged in the next picture) |
|---|---|---|
| A vertical line toward the left; crosses on its right, circles on its left | The three circles to the right of the line | |
| A vertical line toward the right; crosses on its right, circles on its left | The four crosses to the left of the line | |
| A horizontal line toward the bottom; crosses above, circles below | The big circle at the upper right, the cross at the lower right, and the two circles on the left | |
| A horizontal line at mid height; circles above, crosses below | The topmost cross and the two circles at the bottom | |
| A horizontal line toward the top; crosses above, circles below | The four crosses below the line; but the combined already classifies everything correctly |
Lin walks through it step by step: at first all circles and crosses are the same size, the decision stump makes the first cut, three circles are misclassified, and AdaBoost multiplies them by to enlarge them and shrinks the others. Because those three circles are large, the second cut tends to get them right, at the price of sacrificing a few crosses, so the crosses are enlarged. After the third cut, the three cuts voting with their own already form a non-linear boundary that turns. By the fifth cut, separates all the circles and crosses. Lin also points out that one cross and one circle in the picture appear to sit on the boundary, which is a visual effect of the enlarging and shrinking; both are really on the correct side.
This article works out the numbers for the first two cuts: 10 examples with equal weights and 3 wrong on the first cut give , , . The three misclassified circles are each multiplied by 1.528 and the seven correct points each divided by 1.528, so the ratio of the per-example weights is ; the three circles total , equal to the seven points' total . Under these weights (total 42) the second cut gets four crosses wrong, , . , so with only two cuts equals the second cut, which is why the black line coincides with the new cut in both of the first two pictures.
The in the last picture is the very figure used for the motivation on page 7 of the handout. At the bottom of this page the handout writes 'Teacher'-like algorithm works!, and Lin says that the teaching model of a teacher and students is not just imagination; it can really be built with an algorithm like AdaBoost.
Slightly more complicated data: a hundred cuts
Page 22 of the handout switches to a data set with more points, where the boundary between circles and crosses looks to the eye like a sine wave. What the handout prints is the picture: many gray vertical and horizontal lines in the background, and a black boundary that is a staircase-like piecewise line roughly following that wave.
In the lecture Lin plays it from 10 cuts all the way to 100: at 10 cuts a rough shape is already there, at 20 and 30 cuts it gets finer and finer, may not have reached 0 but is already small, and the next few dozen cuts are mostly fine-tuning. Lin draws two conclusions. First, this is a non-linear model: cut after cut is pieced together and the boundary keeps improving. Second, it is efficient: compared with kernel SVM, there is no need to transform the data into another space and then solve a quadratic program; a hundred cuts carve out the boundary. The handout's slogan is AdaBoost-Stump: non-linear yet efficient.
Application: real-time face detection
The example on page 23 of the handout is a system it calls The World's First 'Real-Time' Face Detection Program, with AdaBoost-Stump as its core model. Lin explains what "real-time" means: video runs at about 30 frames per second, and all the faces in a frame have to be found at that speed. The handout lists two points:
- Feature selection. In 24x24 images there are 162,336 possible small-patch patterns that can serve as features. Each decision stump looks at only one feature, so when AdaBoost-Stump finishes it has in effect picked the key few out of these more than 160,000 and combined them linearly. Lin's description: cut the image into many tiny pieces (usually called patches), find which pieces carry the key patterns, and then use AdaBoost to integrate their information. The handout's wording is feature selection achieved through AdaBoost-Stump.
- Efficiency. The above alone is not enough for real time. Lin points out that in a large image only a few positions contain a face and most positions do not. So this program modifies the linear aggregation : partway through the vote, if the score is already very low, it decides right away that this is not a face and stops computing; only positions that might be a face get the whole computed. What the handout writes is modified linear aggregation to rule out non-face earlier.
An addition in this article: the handout does not give this system's name; it is generally known as the Viola–Jones face detector.
The handout's summary of this page: AdaBoost-Stump achieves efficient feature selection and aggregation at once.
Fun Time: how many features are used
Question (page 24): For a data set of size 9876 that contains , after running AdaBoost-Stump for 1126 iterations, what is the number of distinct features within that are effectively used by ?
Answer: 1. Each decision stump takes only one feature, 1126 rounds make 1126 stumps, and they need at most 1126 distinct features. Lin gives the same one-sentence reason in the lecture.
This article adds why the other choices are impossible: choice 2 needs more than 1126 features, but there are only 1126 stumps; choices 3 and 4 go beyond the total number of features, 5566. The real number is usually smaller than 1126, because different rounds can pick the same feature and cut at different thresholds. The 9876 in the question (the number of examples) does not affect the answer. This question is the numerical version of "feature selection" in the previous subsection: of the 5566 features, at least 4440 are never used by at all.
Summary of this lecture and the next one
Page 25 of the handout sums up each of the four sections in one line:
| Section | The handout's one line |
|---|---|
| Motivation of Boosting | aggregate weak hypotheses for strength |
| Diversity by Re-weighting | scale up incorrect, scale down correct |
| Adaptive Boosting Algorithm | two heads are better than one, theoretically |
| Adaptive Boosting in Action | AdaBoost-Stump useful and efficient |
At the end of the lecture Lin places these two lectures side by side: bagging is uniform aggregation, AdaBoost is linear aggregation, and the next lecture introduces conditional aggregation.
Self-check
1. Five examples, . gets two of them wrong. Compute , , , and each example's , and verify that the error rate of under the new weights is .
Answer: , , . The two incorrect examples are each , and the three correct ones are each . The incorrect total is and the correct total is , which are equal.
2. Continue the six-fruit-photo example. After the round 3 update the weights are proportional to . In round 4, what are the weighted error rates of A, B, and C? Which is chosen? What is ? Is still entirely correct after adding it?
Answer: the total is 20. A gets 3 and 4 wrong: ; B gets 5 and 6 wrong: ; C gets 1 and 2 wrong: (the previous round's winner). Choose A, , . A votes for every , so each of the three scores gains : , , . The signs do not change, and is still entirely correct. The same rule can be chosen again in non-adjacent rounds.
3. In some round the base algorithm returns a whose weighted error rate is exactly . What are this round's and ? How do the weights change? What happens afterward?
Criteria: the answer should state , , and that the weights do not change at all; in the next round the base algorithm faces the same weights, and if it is deterministic it returns the same , so the algorithm is stuck in place from then on. It should also connect back to the condition of the theoretical guarantee: this is exactly the case where " in every round" is violated.
4. Why not a uniform vote at the end, and why use instead? Why should a with get 0 votes, while a with does not get 0 votes?
Criteria: the first part should mention that the hypotheses from on are chosen under deliberately distorted weights and are not necessarily good for the original , so they should get different vote weights according to how they perform. The second part should compute that at , and , and explain that a negative vote amounts to using the other way around, with an error rate of when reversed; is the only position where neither side carries information.
5. Use the upper bound added in this article: , and in every round. After at most how many rounds is guaranteed? What if the base algorithm is weaker and can only guarantee ?
Answer: with , and , so 339 rounds. With , and , so 1375 rounds. The closer the base algorithm is to random guessing, the faster the required number of rounds grows, but the dependence on is still only : when goes from 1000 to 1,000,000, the number of rounds only doubles.
Exercises and corresponding reading
The corresponding weeks in two semesters. The Fall 2024 course page covers Techniques Lectures 8 through 11 in one go in W12 (11/18), and the slide code for this lecture is 208u. The Fall 2026 course page puts Lectures 7 and 8 in W11 (11/18); the 208u slides for that week were not yet online when checked on 2026-09-30, so this article uses only the MOOC handout.
Textbook. Neither course page marks a chapter of Learning from Data (LFD) for this lecture. The further reading listed on the course page is A Short Introduction to Boosting by Freund and Schapire, an introduction written by AdaBoost's own authors.
Homework. The problems in Fall 2024 HW7 (released 2024-12-02, due 12-16) that relate directly to this lecture are listed below; there are no official solutions:
| Problem | Type | What it practices |
|---|---|---|
| Q3 | Auto-graded | 87% of the data are negative examples and returns the constant ; the question asks for the weight ratio between positive and negative examples in the second round. The method is the same as in the Fun Time "four examples, one wrong": compute first, then look at the ratio between the incorrect and correct multipliers |
| Q6 | Human-graded | Prove . The problem hints that this is the backbone of the proof that AdaBoost converges within iterations, which is fact one in this article's addition, the one given as a conclusion only; everything the proof needs is in the "scaling factor" subsection |
| Q10–12 | Human-graded | Implement AdaBoost-Stump on LIBSVM's madelon (training) and madelon.t (test), run the full rounds, and plot the curves of and , of and , and of |
Q10 requires extending the decision stump from HW2 to a multi-dimensional version that takes weights. The simplest way is to find the best stump for each feature and then pick the best over all features. There are no official solutions, so you have to set your own acceptance test: you can use scikit-learn's AdaBoostClassifier with depth-1 decision trees as a reference and see whether the trend of agrees; you can also check your implementation first on the six-example data above, where the three rounds' should be . This article ran scikit-learn 1.9.1 on these six examples: the first four values of estimator_errors_ are , the same as the hand computation; estimator_weights_ is , exactly twice the handout's . Multiplying all the vote weights by the same positive number does not change , so when using it as a reference, compare and and do not compare the vote weights directly. The guide to the whole assignment is in Techniques Homework and Final Project.
One thing you can do tonight. Change the program above to 2D: place a dozen or so circles and crosses yourself, and in each round print the few points with the largest weights. You will see that they are mostly the ones near the boundary that keep being misclassified, which is what the teacher is doing.
Next lecture. Techniques Lecture 9: Decision Trees covers the third way of combining: conditional aggregation, where different listen to different hypotheses. AdaBoost itself appears once more in Techniques Lecture 11, which explains where the choice comes from.
Course video sources
Original videos: Motivation of Boosting, Diversity by Re-weighting, Adaptive Boosting Algorithm, Adaptive Boosting in Action
Checked: 2026-10-13. The video IDs, titles, and lengths were taken from the official playlist on that day; the videos have no caption track on YouTube, and what this article reports from the lecture comes from transcripts made for it.
Update Log
- 2026-10-13: The series now has one article per lecture; this lecture is a newly split-out article, written from the handout and the video transcripts.
References
- Techniques Lecture 8 handout, 208_handout.pdf: the main source for this article. The derivations in the four sections, the four Fun Time questions, the demonstration figures on pages 21 and 22, and the face detection on page 23 all come from this handout.
- Machine Learning Techniques 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 entry for handouts and recordings.
- Machine Learning, Fall 2024 course page: the corresponding week, the 208u slides, and the further reading list.
- Machine Learning, Fall 2026 course page: the corresponding week.
- Fall 2024 Homework 7 (hw7.pdf): the content of Q3, Q6, and Q10–12.
- LIBSVM Data: madelon: the data set used in HW7 Q10–12.
- Freund & Schapire, A Short Introduction to Boosting: the further reading listed on the course page.
- Learning from Data textbook website: the textbook the course pages map chapters to; this lecture has no corresponding chapter.
- Reading NTU Hsuan-Tien Lin Machine Learning Foundations & Techniques: Course Overview: where this lecture sits in the whole course and the reading routes.
Loading...