🌏 中文版
Video status: Videos included. This article is written from the official MOOC handout 207_handout.pdf and transcripts of the 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/23 to 23/23), and wherever the text says "in the lecture" it is paraphrasing what is said in the video.
This is Techniques Lecture 7 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. The first six lectures all belong to the first, Embedding Numerous Features: Kernel Models, which wraps up with the previous lecture, Techniques Lecture 6: Support Vector Regression. This lecture starts the second: Combining Predictive Features: Aggregation Models. The question changes. You already have several hypotheses, each with some predictive power; how do you combine them into something better than any one of them alone? In the lecture, Lin says this family takes five lectures, each introducing a few different approaches, and this is the first.
The prerequisites are the and notation from Foundations Lecture 15: Validation, the squared error from Foundations Lecture 9: Linear Regression, the "transform first, then run a linear model" flow from Foundations Lecture 12: Nonlinear Transformation, and basic manipulation of expectations. After reading, you should be able to re-derive the error decomposition of uniform blending on your own and say which term is the bias and which is the variance; carry out linear blending and any blending step by step and explain why the ballots have to be learned on validation data; and write down the bagging procedure and work out what a bootstrap data set looks like.
Why combine hypotheses: from picking one friend to letting everyone vote
(Video 00:17–02:03 reviews the previous lecture and previews the topic, 02:03–05:18 is the story of friends tipping stocks, 05:18–10:34 writes the four approaches as formulas, 10:34–12:59 covers the limits of selection, 12:59–17:49 covers the two illustrations, followed by Fun Time.)
Four ways to use your friends
The story on page 2 of the handout goes like this. You have friends , each of whom predicts whether a certain stock will go up or down tomorrow; friend 's prediction is written . In the lecture, Lin simply assumes 15 friends, some saying up and some saying down. Having heard them, you can:
- Select the most trustworthy one and listen only to that friend. You choose by each person's usual performance. The handout marks this with "validation": it is the model selection of Foundations Lecture 15.
- Give everyone one vote. If the majority says up, call it up.
- Vote, but with unequal ballots. The more trustworthy friends get a few more ballots.
- Decide whom to listen to depending on the situation. The handout's wording is: if " satisfies some condition", give some ballots to friend . The example in the lecture is that some friends are good at technology stocks and others at traditional industries; for a technology stock you consult friends A, B, and C, and for a traditional-industry stock you switch to A and D.
The handout calls all of these aggregation models: mix or combine hypotheses, for better performance.
The four approaches as formulas
Page 3 writes each of the four as one line. Up is , down is , and the final result is the capital .
Select one (select):
is the version learned from the training data only (without the validation data), and its validation error is what you select by. Once is chosen, what you return is learned from all the data; this is the procedure from Foundations Lecture 15.
One vote each (uniform):
Add up everyone's and look at whether the sum is positive or negative.
Unequal ballots (non-uniform):
is the number of ballots friend gets. In the lecture, Lin says the number of ballots of course cannot be negative, but it can be 0, meaning this person's vote is not needed at all.
Conditional (conditional):
The ballot count changes from a fixed number into a function of . The explanation in the lecture: if the input records which kind of stock this is, can use that information to decide whether to ask friend and how many ballots to give.
The four forms are nested one inside the next. The handout uses for "1 when the condition holds, 0 when it does not":
| The larger form | The setting that reduces it to the smaller form |
|---|---|
| non-uniform | : only the one with the smallest validation error gets 1 ballot and everyone else gets 0, which is select |
| non-uniform | : this is uniform |
| conditional | : the same ballots under every condition, which is non-uniform |
So conditional contains everything before it. The handout's summary is "aggregation models: a rich family".
The limits of selecting just one
Page 4 looks back at selection. It is simple and popular, but two things are worth remembering:
- If you select with instead of , you pay a complexity price on . Foundations Lecture 15 covered this, and it is used once more in this lecture when linear blending comes up.
- For selection to succeed, the candidates must include one strong , which guarantees a small and in turn a small . In the lecture, Lin puts it bluntly: if every is weak, then however you select, you are only picking one out of a bad bunch.
The handout sets the two side by side in two sentences. Selection relies on one strong hypothesis, which the lecture calls strongman leadership. Aggregation asks: with many (possibly weaker) hypotheses in hand, can we do better by combining them?
Two pictures: combining can make things stronger, and also steadier
Page 5 uses two pictures to answer "why might aggregation work?" Both show circles (positive examples) and crosses (negative examples) on a two-dimensional plane.
Left picture: weak ones combine into a strong one. The rule is that only horizontal or vertical lines may be used to classify. In this data set the circles sit at the upper right and the crosses at the lower left, so it looks as though at least a slanted line is needed to separate them, and no single horizontal or vertical line does well. The picture draws one horizontal line and two vertical lines, none of them perfect on its own. After the three get one vote each, the resulting boundary is a staircase-shaped polyline that goes down, right, and down again, separating the circles and crosses completely. The handout's note is: mix different weak hypotheses uniformly and becomes "strong", an effect like a feature transform.
Right picture: many lines that are all correct combine into the one in the middle. This data set is linearly separable, and infinitely many lines separate it perfectly. When PLA runs with randomness it may stop at any one of them, and the picture draws a bundle of gray lines. Let these gray lines vote and the result is the black line in the middle. The explanation in the lecture: the gray lines are spread across all the feasible lines, so the vote lands near the moderate one and does not hug any particular circle or cross; and the moderate line is roughly the line with the fatter boundary, so the effect resembles the large margin of SVM, that is, regularization. The handout's note is that becomes "moderate".
In the lecture, Lin points out that these two things pull in opposite directions in Foundations: a feature transform is like stepping on the accelerator, giving the model more power, and regularization is like stepping on the brake, keeping the model from being so powerful. The same act of letting hypotheses vote can produce either effect. Doing aggregation right is like having both the accelerator and the brake under control. The conclusion on this page of the handout is "proper aggregation ⟹ better performance", and both effects carry a question mark; this article's reading is that the two pictures give intuition, not yet a proof. One effect addresses a model that lacks power and the other addresses overfitting, and both show up once more when the last aggregation lecture, Techniques Lecture 11: Gradient Boosted Decision Trees, sums everything up.
Fun Time: three decision stumps vote
Question (page 6): Consider three decision stump hypotheses from to : , , . When mixing the three hypotheses uniformly, what is the resulting ?
First, read the notation in the choices: when holds it is 1 and ; when it does not hold it is 0 and . So choice 1 means "output when and everywhere else". A decision stump is a classifier that looks at one dimension and makes one cut; cuts at , cuts at , and is the constant that says whatever the input.
Answer: 1. Split the number line into three segments and count the votes on each:
| Region | Vote total | ||||
|---|---|---|---|---|---|
Only the middle segment gets the two positive votes from and at once, beating the single negative vote from . Choice 2 swaps inside and outside. Choices 3 and 4 each have only one cut point, but the result of the vote has two.
An addition in this article: at exactly the two points , one of the stumps evaluates . Taking as makes these two points as well, which is what it takes to match the "" in choice 1 exactly.
The handout's answer adds one sentence: the three decision stumps can be aggregated to form a more sophisticated hypothesis. Each stump can only cut the number line into a left side and a right side, yet carves out "a segment in the middle". In the lecture, Lin says this is a bit like the left picture on page 5: combining a bunch of simple hypotheses makes something more complex.
Why one vote each works: uniform blending and the error decomposition
(Video 00:00–04:17 is voting for classification, 04:17–06:46 is averaging for regression, 06:46–15:24 derives the error decomposition, 15:24–19:54 is the virtual process and bias–variance, followed by Fun Time.)
The word blending, and voting for classification
The lecture starts with the terminology. Blending is what a blender does: throw a bunch of hypotheses in and turn them into one glass of mixed juice. The word is used when the are already in hand; say you lead a team of three, each member hands you a , and the only question left is how to combine them. When every has equal standing and one vote, it is called uniform blending.
The formula for binary classification (page 7) is the line from before:
The handout lists two extreme cases:
- All are the same (the handout jokingly calls this autocracy): the vote gives that one , with no benefit at all.
- The are very different (diversity plus democracy): the majority can correct the minority.
The picture on the right of page 7 is the actual voting result for the left picture of page 5. The explanation in the lecture: one horizontal line and two vertical lines cut the plane into six pieces; in each piece the three lines each give an answer and you take the side with two votes. The whole upper-right area comes out as circles and the whole lower-left area as crosses, and the staircase boundary is what this vote counting produces. "The minority yields to the majority" can correct mistakes, and the assumption behind it is that the minority side is the one more likely to be wrong.
Multiclass classification can vote too, except that instead of adding and subtracting you count how many votes each class gets and pick the highest:
An example from this article: five hypotheses say classes 2, 1, 2, 3, 2 for the same ; class 2 gets three votes, so .
Regression: average the outputs
Regression outputs are real numbers, and the approach on page 8 is to average:
Why divide by ? The example in the lecture: the correct answer is 2, ten people all predict something near 2, and adding them directly gives 20. To give one vote each and still land in the same range, you have to divide by the head count.
The two extreme cases are the same as in classification. When the are all the same, the average is still that one hypothesis. When the differ, the handout writes: some , some , and the average "could be" more accurate than the individual ones. Overestimates and underestimates cancel in part.
The handout wraps the two pages into one sentence: with diverse hypotheses, even simple uniform blending can be better than any single hypothesis. The "can be" in that sentence is turned into a definite inequality next, with a short piece of algebra.
Derivation: average error equals spread plus the error of G
What page 9 proves is that the average squared error of the and the squared error of differ by exactly one term, "how spread out the are".
First, the notation. In the lecture, Lin says dragging behind every function is too much trouble, so fix one and abbreviate , , to , , ; all three are just numbers. Also let mean "sum over and divide by ", so . Lin remarks that writing avg is friendlier than the summation sign.
This has two properties, and the whole derivation rests on just these two: it is linear (sums can be split and constants pulled out), and the average of a quantity that does not depend on is that quantity itself. Neither nor depends on .
What each line does:
- Expand the square.
- Split the average over the three terms. The first term stays. The middle term is , because is a constant and is . The last term is .
- Complete . The target contains the error of , ; we have and are short one . In the lecture, Lin describes this as borrowing a and then paying it back, which leaves an extra .
- Write as . Lin calls this a magic trick; the purpose is to let the first half form a square as well.
- Put back inside the average. , which turns one of the 's back into "the average of the "; and , because does not depend on .
- Recognize the perfect square. .
The conclusion, for this fixed :
Numerical example: three predictions
The following is an example made up for this article, not from the slides. Fix one ; the true answer is and the three hypotheses predict , , . Two underestimate and one overestimates.
- .
- Left-hand side: .
- Spread: .
- Error of : .
, so the identity holds. The squared errors of the three hypotheses are 16, 4, and 9, averaging close to 10; the averaged has only 1, and in this example beats all three.
But the identity only guarantees "no worse than the average". Change the predictions to , , with still 6: , the error of is 9, the average error of the is , the spread is , and still holds. Yet the error of is 0, better than . This is exactly the point made in the lecture: whether the best beats is unknown; what is certain is that beats the expected performance of "picking a at random", because you do not know in advance which one to pick.
From one point to the overall Eout
The identity above holds for every , so you can take the expectation over the distribution that generates . The handout writes this expectation as . The expectation of the squared error is : and . Both and are linear operations and their order can be swapped, so the lower half of page 9 reads
The middle term is an average of squares followed by an expectation and cannot be negative; drop it and you have the inequality. In regression with squared error, the of uniform blending is guaranteed to be no worse than the average performance of the , and the gap between the two is exactly the spread among the : the more the differ, the more wins by; when the are identical that term is 0 and there is no benefit. The earlier "be diverse" now has a precise meaning.
An addition in this article: this conclusion is proved for the squared error of regression. Voting in classification has no identity this clean; Self-check question 2 works a classification example with probabilities.
Some special gₜ: bias and variance
Page 10 applies the same identity to a special set of . Imagine a virtual process that, for :
- Requests a fresh size- data set from the distribution (i.i.d.).
- Obtains with the algorithm .
In the lecture, Lin says this process is abstract and leaves what is impractical about it for later; the bagging section shows that the problem is that nobody can get a brand-new data set every round in reality. Push to infinity and write the result of the averaging as :
is the expected value of the hypothesis the algorithm produces after seeing all kinds of data. Replace with and the earlier identity becomes
An addition in this article: the identity still holds after the swap because the derivation used only the linearity of the average and the fact that is the average of the . Replace "average over " with "expectation over the data " and both properties are still there.
The handout gives each of the three terms a name:
| Term in the formula | The handout's wording | Name |
|---|---|---|
| expected performance of | — | |
| performance of consensus | bias | |
| expected deviation to consensus: how far each is expected to deviate from the consensus | variance |
is called the consensus, the shared opinion of all the . The plain-language version in the lecture: bias looks at how far this consensus still is from the we really want; variance looks at how messy the opinions are when this crowd of all talk at once. The average performance of an algorithm splits into these two terms, which statistics books call the bias–variance decomposition.
The conclusion on this page of the handout: uniform blending reduces variance for more stable performance. In the lecture, Lin explains that the averaging process removes the influence of the "how messy the opinions are" term. The identity shows it too: once you use the consensus , the error is only the one bias term , and the variance term disappears entirely. The bias, on the other hand, does not shrink because of averaging; however far the consensus is from , that is how far it stays.
Numerical example: learning a constant from one example
The following is an example made up for this article, not from the slides; its purpose is to put a number on each of the three terms.
- The input takes , , with equal probability and the target function is , so the values of are 1, 0, 1.
- Each data set has only example. The algorithm returns the constant hypothesis through that example, .
There are three equally likely data sets, and the learned is the constant 1, 0, 1 respectively. The of a constant hypothesis is :
| The drawn | The learned | ||
|---|---|---|---|
- Consensus: .
- Expected performance of the algorithm: .
- Variance: . Because is a constant, does not change with , so its expectation over is itself.
- Bias: .
, so the identity holds. What this result says: for an algorithm that draws its conclusion from a single example, half of the expected error comes from "the data seen is different each time, and what is learned wobbles along with it". If you could average all the possible , the error would drop to , lower than each of the three ( or ). The remaining is the part of that a constant hypothesis cannot express in the first place, and no amount of averaging removes it.
Fun Time: what an average of linear hypotheses is
Question (page 11): Consider applying uniform blending on linear regression hypotheses . Which of the following properties best describes the resulting ?
- a constant function of
- a linear function of
- a quadratic function of
- none of the other choices
Answer: 2. The inner product is linear in its first argument, so
is still a linear hypothesis, and its weight vector is the average of all the . Choice 1 holds only when the averaged weights happen to make not change with , which is not the general case. Choice 3 is impossible; adding linear functions does not grow a quadratic term. The handout also explains why it writes innerprod: the T in the usual transpose notation would clash with the number of hypotheses .
An addition in this article: this question and the "three decision stumps vote" Fun Time form a matched pair. An average of linear regression hypotheses stays inside the original hypothesis set, so the model gains no power, and the only thing averaging can bring is lower variance. When decision stumps vote there is an extra layer of , and the combined lands somewhere a single stump cannot express. Of the two pictures on page 5, one is about gaining power and the other about becoming steadier; the stump question is a small instance of the former, and this linear regression question is the plainest case of "steadier only, with no change in power" (the PLA vote in the right picture has an extra layer of , so it is not exactly the same).
How the ballots are decided: linear blending and any blending
(Video 00:00–03:44 views linear blending as a linear model, 03:44–06:18 covers the constraint , 06:18–11:10 compares with selection and gives the practical steps, 11:10–12:49 is any blending, 12:49–16:11 is the KDD Cup 2011 story, followed by Fun Time.)
Finding the ballots is one run of linear regression
Linear blending (page 12) likewise assumes the are already in hand and decides how many ballots each gets:
The explanation in the lecture for the word linear in the name: is a linear combination of the outputs of the , with the as coefficients. What is a good ? The most direct idea is to minimize the error, . Taking regression as the example, the handout puts it side by side with a problem learned in Foundations:
| linear blending for regression | LinReg + transformation |
|---|---|
The two sides match term by term: with , with , and the number of hypotheses with the transformed dimension . The only difference is the extra on the left. So the handout writes linear blending as one line:
linear blending = LinModel + hypotheses as transform + constraints
In the lecture, Lin says linear blending really contains nothing new: treat the as a feature transform and all that remains is the linear models already learned, linear regression for regression and logistic regression when you want to output probabilities. The handout notes that this is like two-level learning. Lin points out that this appeared with the probabilistic SVM (Techniques Lecture 5: Kernel Logistic Regression): run SVM first, then hand its output to logistic regression. Here you get a set of first, then run a linear model once to get .
Can ballots not be negative?
A linear model has no constraint like to begin with, and adding it means the ready-made solvers no longer apply directly. Page 13 first switches the error to the general form and then asks: if the solution has some , what does that mean?
Giving a negative number of ballots equals giving a positive number. In binary classification, is with its answers flipped. In the lecture, Lin puts it this way: when the machine finishes learning and comes out with a negative , it is suggesting you use this the other way round.
The handout makes the point that there is nothing wrong with flipping by way of a joke: if you have a stock up/down classifier with 99% error, tell me! The lecture finishes the thought: when it says up I guess down, and when it says down I guess up, so 99% error becomes 99% accuracy.
So the handout's conclusion is that in practice the constraint is often simply dropped, and "+ constraints" is struck through on the slide:
linear blending = LinModel + hypotheses as transform
Lin also concedes in the lecture that for regression the meaning of using a hypothesis flipped is less intuitive, but most of the time there is no need to keep this constraint on purpose.
Numerical example: computing ballots for three decision stumps
The following is an example made up for this article, not from the slides; the hypotheses are the three decision stumps from two of the handout's Fun Time questions, , , .
Treat the hypotheses as a feature transform, . Points on the number line have only three possible images:
| Region | |
|---|---|
Take five data points to learn the ballots, using linear regression without the constraint, that is, finding the that minimizes . If some makes the error on every point 0, it is the minimum, so solve "one equation per region" directly:
The second equation minus the first gives , the second minus the third gives , and substituting back into the second gives . Solve once for each of three different targets:
| Target (the region where ) | The solution | What these ballots mean | |
|---|---|---|---|
| One vote each, which is uniform blending | |||
| Keep only , which is selection | |||
| Use flipped |
Take the third row: , so ; , so ; . Check: at , ; at it is ; at it is also ; all five points match exactly. Hand the and of these five points to the linear regression solution from Foundations Lecture 9 and compute once more, and you get the same answer.
This small example walks through all three things in this section. With the same hypotheses and the same linear regression, different data produce ballots that can be uniform or can be selection, which is the nesting table from page 3. The in the third row is negative: these three equations have only this one solution, so insisting on makes zero error unreachable; allowing negative ballots amounts to having one more hypothesis available, .
The three stumps in this example are given in advance, not learned from these five points. In practice the are usually learned from data as well, and then which data you use to learn the ballots matters; that is handled next.
Ein cannot be used to learn the ballots
Where do the usually come from in practice? Page 14 says: each from a different model, , each obtained by minimizing within its own hypothesis set. This is the same setting as model selection in Foundations Lecture 15, and the conclusions from then apply:
- Selection by picks the best of best, and the complexity price to pay is . The analogy in the lecture is that the top students of two classes come out and compete once more, and whoever is picked represents the complexity of the two classes combined.
- Linear blending includes selection as a special case, by setting to .
- So linear blending with , which the handout calls aggregation of best, has a complexity price .
The reason for the third point, as given in the lecture: selection only picks one out of the class champions, while linear blending assembles all the champions into an elite team; what it can do includes selection, so the price paid can only be higher. Best of best is already dangerous enough and this overfits even more easily, so learning with is not recommended in practice.
The handout's prescription is the same as for selection, with two replacements: use instead of ; and the hypotheses being combined are the , the versions obtained by minimizing on only. In the lecture, Lin adds the purpose of the second point: the validation data used to compute has to be separate from the data that produced those hypotheses, so that there is independence.
The practical steps, and any blending
Page 15 writes out the procedure. After splitting the data into and :
- Learn on .
- Transform every in into , where .
- Learn how to combine on the transformed data.
- The returned uses instead, that is, the without the minus sign.
Steps 3 and 4 come in two versions:
| Linear Blending | Any Blending (Stacking) | |
|---|---|---|
| Step 3 | ||
| Step 4 |
What means, as explained in the lecture: first compute the inner product of and ; for regression output it directly, and for classification take of it.
Why does step 4 use and not ? Lin stops to explain this in the lecture: it is the same reasoning as returning and not after validation has selected a model; used all the data and is expected to perform better than . An addition in this article: this means every model is trained twice, once on only to get for learning , and once on all the data to get for the final prediction.
The right-hand column swaps the linear model for an arbitrary model. The handout names this any blending, also called stacking. In the lecture, Lin explains that stacking means one layer piled on another: the first layer gets the and the second layer combines them, and the second layer can be a nonlinear SVM or whichever model you want to use. There is also a joke: the Lin in LinearModel stands for linear, not for the lecturer's surname.
The handout has two remarks on any blending:
- powerful: the second layer is nonlinear and can achieve the conditional blending of page 3, which amounts to using different under different conditions.
- danger of overfitting: the more powerful a model, the more easily it overfits. In the lecture, Lin warns that any blending has to be used very carefully, with regularization added wherever it is called for and the brake applied often.
A real case: KDD Cup 2011 Track 1
Page 16 is the solution with which the NTU team won the KDD Cup 2011 Track 1 world championship; the source is the paper by Chen et al., A linear ensemble of individual and blended models for music rating prediction. The flow chart at the top of the slide has five boxes, in order:
- Data-Set
- Single Models: the arrow comes from Data-Set; many single models are trained, and they are the of this lecture.
- Val.-Set Blending: the arrow comes from Single Models, with another one directly from Data-Set.
- Test-Set Blending: the arrow comes from Val.-Set Blending, with another one directly from Single Models.
- Post-Processing
In other words, both the single models and the models produced by the first blending go into the second blending.
Each of the two blendings has numbers, which the handout labels (squared):
| Step | Method | What the handout says it did | |
|---|---|---|---|
| validation set blending | a special any blending model | 519.45 ⟹ 456.24 | helped secure the lead in last two weeks |
| test set blending | linear blending using | 456.24 ⟹ 442.06 | helped turn the tables in last hour |
This article worked out the reductions: the first step lowered it by 63.21, about 12.2%; the second step lowered it by 14.18, about 3.1%.
The lecture fills in how the competition went. The first step combined the single models in a nonlinear way, and after it the NTU team stayed steadily in the leading group over the last two weeks of the competition. The second step combined the hundred or more and obtained so far once more, this time only giving each model a different number of ballots; what was special is that some method made it possible to get an estimate very close to , which is what the tilde over on the slide means, and the ballots were then learned directly against that estimate. The reduction in the second step looks small, yet it took the NTU team from second place to first in the last hour of the competition.
The handout's conclusion is that blending is "useful" in practice, despite the computational burden. Lin discounts this in the lecture too: whether a competition counts as practice is one question, and whether a real system would hold more than two hundred models is another; what is certain is that if you have tried things from different directions and have some different in hand, combining them really does help, at the cost of model complexity and computation.
Fun Time: the transformed result at x equal to 0
Question (page 17): Consider the same three decision stump hypotheses, , , . When , what is the resulting used in the returned hypothesis of linear/any blending?
Answer: 2. Substitute directly: , , . The handout's answer is a single line, "Too easy? :-)".
The other choices map back to the table in the earlier example: choice 3 is the of the segment . Choices 1 and 4 never occur for any : the third component of choice 1 is , but is always ; choice 4 needs and to be at once, which requires and .
What this question checks is whether "hypotheses as transform" has sunk in: the originally one-dimensional is turned by three hypotheses into a three-dimensional , and the second-level model sees , not the original .
Getting different hypotheses from a single data set: bootstrap and bagging
(Video 00:00–03:00 reviews blending and lists the sources of diversity, 03:00–04:30 returns to bias–variance, 04:30–06:42 is bootstrap, 06:42–08:12 is bagging, 08:12–09:46 is the pocket demonstration, followed by Fun Time and the summary.)
From "get the gₜ, then combine" to "combine while learning the gₜ"
Page 18 first sorts out the three kinds of blending so far and raises the next question. Blending aggregates after getting the ; the handout calls "aggregate as well as getting " learning:
| aggregation type | blending | learning |
|---|---|---|
| uniform | voting/averaging | ? |
| non-uniform | linear | ? |
| conditional | stacking | ? |
This lecture fills in only the first cell of the right-hand column. Compared against the same table at the start of the Techniques Lecture 9 handout, the answers to the three cells are, in order, Bagging, AdaBoost, and Decision Tree; the last two are the content of the next two lectures.
To learn the for uniform aggregation, the earlier analysis has already named the key: diversity. The handout lists four sources of diversity:
- Different models: .
- Different parameters: for example, gradient descent with . The lecture adds SVM with different or different .
- Algorithmic randomness: random PLA with different random seeds. Lin says pocket with different starting points counts too.
- Data randomness: the within-cross-validation hypotheses , each learned from a different set of folds.
The handout takes the fourth route next, with one added condition: diversity by data randomness without . This article's reading is that every from cross-validation uses one fold less data; what is wanted here is a way to build many different from the same data set without carving out validation data.
Back to bias–variance: two things that cannot be done
Page 19 returns to the conclusion of the uniform blending section:
The handout says the consensus is more stable than the direct , but it comes from many more than the one on hand. The lecture splits the difficulty in two: is an average of infinitely many , and we do not have infinitely many; every needs a fresh data set, and we have only the one in hand. So two compromises are needed:
- Use a finite but large in place of infinitely many.
- Using only the in hand, find a way to build a that "looks like new data", and use it to get .
The second compromise relies on bootstrapping. The handout's definition: a statistical tool that re-samples from to "simulate" .
Bootstrap: re-sampling with replacement
The definition on page 20: a bootstrap sample is the data obtained by re-sampling examples from uniformly with replacement.
With examples in hand, isn't drawing of them just the original set? The lecture makes the process concrete: grab one example, note down "this time I drew example 3", and put it back; grab another, note down "this time I drew example 5", and put it back; grab another, example 3 once more, note it down too, and put it back. Because each one goes back, the same example may be drawn several times, and some examples may never be drawn. Do this times, and the examples noted down are one bootstrap sample. The tilde indicates that it resembles the imagined but is not the same.
The number drawn does not have to be ; the handout says an arbitrary can be used. The example in the lecture: with 10,000 examples, if drawing 3,000 each time seems enough, then is 3000. What matters is the process of "draw, note down, put back".
The bagging procedure
With bootstrap, the virtual process of page 10 can be replaced by a version that can actually be carried out. The handout puts the two side by side:
| virtual aggregation (virtual) | bootstrap aggregation (physical, can actually be done) | |
|---|---|---|
| For each round , step 1 | Request a fresh size- data set from | Draw a size- data set from by bootstrapping |
| Step 2 | ||
| Finally |
is the uniform blending of this lecture: voting for classification, averaging for regression. The two columns differ only in where the data comes from.
Bootstrap aggregation is abbreviated BAGging. In the lecture, Lin says the nickname is like bagging up a bunch of . It does not care what the underlying is and can be applied to every algorithm, so the handout calls it a meta algorithm on top of the base algorithm .
Numerical example: bootstrapping three examples
The following is an example made up for this article, not from the slides. The data has only three examples, with values 1, 2, 6; ignore the input and learn just a constant to predict . Three draws with three possibilities each give equally likely ways to draw. Ignoring order, there are 10 combinations:
| The three drawn | Number of ways | Mean | Median |
|---|---|---|---|
| 1, 1, 1 | 1 | 1 | |
| 1, 1, 2 | 3 | 1 | |
| 1, 1, 6 | 3 | 1 | |
| 1, 2, 2 | 3 | 2 | |
| 2, 2, 2 | 1 | 2 | |
| 2, 2, 6 | 3 | 2 | |
| 1, 2, 6 | 6 | 2 | |
| 1, 6, 6 | 3 | 6 | |
| 2, 6, 6 | 3 | 6 | |
| 6, 6, 6 | 1 | 6 |
The numbers of ways add up to 27. Of the 27 ways, only 6 draw exactly the original three examples; the other 21 all contain a repeat and all miss at least one example. Each round's mostly differs from and from the others, and that is where the differences among the come from.
Now look at two base algorithms. With very large, the output of bagging approaches the average over the 27 ways:
- returns the mean. On the original data . Average the means of the 27 ways and you still get 3. The individual are all different, yet combined they return to the starting point.
- returns the median. On the original data . Among the 27 ways the median is 1 in 7 of them, 2 in 13, and 6 in 7, and the average is , different from the original 2.
This example shows two things. First, the of bagging does not necessarily equal the result of running once on ; the median case differs. Second, bootstrap only re-samples from the same and brings in no new data. The mean case shows it most clearly: every example has the same probability of being drawn, so the expected value of the bootstrap mean is the mean of the original data, and re-sampling and then averaging only returns to . The of the virtual process is an expectation over truly new data, and the two are not the same thing; when covering bagging in the lecture, Lin also says this only simulates that imagined process. These two points are what this article reads out of the example, not content from the handout. The example has no , so there is no way to say which answer is better; it only shows what bagging changes and what it does not.
Demonstration: bagging plus pocket
Page 21 is a picture from an actual run, with the pocket algorithm from Foundations Lecture 2 as the base algorithm. The setting is and : bootstrap 25 times, let pocket run 1000 rounds on each data set, and get one line from each.
The 25 gray lines in the picture point in very different directions; the lecture describes some as closer to horizontal and some as slanted, and all of these differences are caused by bootstrap. After the 25 lines vote you get the black boundary, a winding nonlinear boundary. The assessment in the lecture is cautious: the circles and crosses are separated acceptably, not extremely well, but possibly better than a single pocket line.
The handout sums it up in two points: the from bagging are very diverse; and aggregating the binary classifiers gives a proper nonlinear boundary. The conclusion on this page: bagging works reasonably well if the base algorithm is sensitive to data randomness. The explanation in the lecture is that the more sensitive the algorithm, the more the bootstrapped differ, and the more likely it is that combining them helps. This sentence sets up Techniques Lecture 10: Random Forests: a fully grown decision tree is exactly an algorithm that is very sensitive to the data.
Fun Time: the probability of drawing the original set back
Question (page 22): When using bootstrapping to re-sample examples from a data set with examples, what is the probability of getting exactly the same as ?
Answer: 3. The handout's solution considers re-sampling in an ordered manner for steps: each step has possibilities, giving possible outcomes in total, each with equal probability. Of these, are permutations of the original , with every example appearing exactly once and only the order differing, so the probability is .
When reading the question out in the lecture, Lin adds a condition: the original examples are distinct. The question also takes "the same" to mean the same regardless of order.
Where the other choices go wrong: choice 1 says it is impossible, but drawing every example exactly once does happen. Choice 2 counts only the one outcome "drawn in the original order", which would be right if even the order had to match. Choice 4 says they are always the same, ignoring the cases where the same example is drawn repeatedly.
A check by this article: in the three-example case above, 6 of the 27 ways are permutations of the original data, , which matches the 6 ways in that row of the table. As grows this probability falls fast: for it is and for it is . With even slightly more data, every bootstrap data set is almost certain to differ from the original.
The summary on page 23 wraps each of the four sections into one line: the aggregated can be strong and/or moderate; hypotheses should be diverse, "one vote, one value"; linear and any blending are two-level learning with hypotheses as transform; and bootstrapping is for diverse hypotheses. The preview of the next lecture is "getting more diverse hypotheses to make strong". The way the lecture puts it: can we get hypotheses even more different than those from bagging, so that does better.
Self-check
1. Fix one with ; three hypotheses predict , , . Compute , the average squared error of the , the spread of the around , and the squared error of , and check the identity. Does beat every ?
Answer: . The average squared error is ; the spread is ; the squared error of is . , so it holds. The error of , 4, is far below the average , but (error 1) and (error 0) are both better than . The identity guarantees that is no worse than the average, not that it beats the best one.
2. Three binary classifiers each have a 20% probability of being wrong, and whether each is wrong is independent of the others. What is the probability that the one-vote-each is wrong? What if the three classifiers are identical? What if each has an error rate of 60%?
Answer (this article's calculation; independence is an assumption given by the question): is wrong when at least two are wrong at once, with probability , lower than the 0.2 of a single one. When the three are identical, the vote is just that one classifier and the error rate stays 0.2, which is what the handout calls autocracy. With an error rate of 60% it is , worse than a single one: the majority corrects the minority only on the premise that the majority is more likely to be right.
3. In linear blending, why is learned on from the outputs of the , while what is returned in the end uses the ?
Criterion: the answer should state three things. First, linear blending includes selection as a special case, so learning with pays a complexity price of at least and overfits easily. Second, the have seen only , so is unseen data for them, and learning is then not misled by data already memorized. Third, once the ballots are fixed, you switch back to the trained on all the data, for the same reason that validation returns and not after selecting a model.
4. Using the three decision stumps from the main text, do linear blending without the constraint, with the target " when and when ". Solve for and explain what it means.
Answer: . , so ; , so ; . : all three hypotheses are used flipped and then given one vote each. This is the opposite of the in the Fun Time question, with all three ballots negative; it cannot be done under the constraint .
5. With distinct examples, bootstrap draws 4. What is the probability that the data drawn is exactly the same as the original (ignoring order)? What does this mean for bagging?
Answer: . With more than a nine-in-ten chance some example is drawn repeatedly while some example is not drawn at all, so each round's mostly differs from , and that is why the base algorithm gives different .
Exercises and corresponding reading
The corresponding weeks in two semesters. The Fall 2024 course page puts this lecture in W11 (11/11), with the slide code 207u. The Fall 2026 course page puts it in W11 (11/18), taught in the same week as Techniques Lecture 8; that week's slides were not yet online as of 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, so this article follows only the handout and the videos.
Homework. The related questions are in Fall 2024 HW6 (released 2024-11-18, due 12-02) and HW7 (released 12-02, due 12-16), with no official solutions:
| Question | Type | What it practices |
|---|---|---|
| HW6 Q4 | Auto-graded | Uniform blending of 5 classifiers whose errors are independent and which each have ; roughly what the of is (the question cites page 7 of handout 207 directly). The calculation is the same as in Self-check question 2 |
| HW6 Q9 | Human-graded | Combining the of linear blending with kernels: take scaled decision stumps on integer inputs as the and derive the corresponding kernel |
| HW7 Q1 | Auto-graded | With , how many examples bootstrap must draw before the probability of a repeated example exceeds 70% |
| HW7 Q5 | Human-graded | The tightest upper bound on when classifiers vote uniformly |
The hint for HW6 Q9 attaches an early paper by Lin, infkernel.pdf. For HW7 Q1 you can check your analytic solution with a Monte Carlo simulation. The guide to the whole assignments is in Techniques Homework and Final Project.
Further reading. Among the further reading listed on the course page, two items relate to this lecture: Breiman, Bagging Predictors (UC Berkeley Technical Report 421) is the original bagging paper; Chen et al. is the KDD Cup 2011 solution cited on page 16 of the handout. How other courses on this site cover the same topic: Harvard CS181 HW4: Decision Trees, Random Forests, and MoE and the Stanford CS229 guide.
Next lecture. Techniques Lecture 8: AdaBoost picks up the question this lecture leaves behind: bootstrap gets different through random sampling; can the data be adjusted deliberately so that the next differs even more from the previous one?
Course video sources
Original videos: Motivation of Aggregation, Uniform Blending, Linear and Any Blending, Bagging (Bootstrap Aggregation)
Checked: 2026-10-13. The video IDs, titles, and lengths were taken from the official playlist 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-10: Marked the video status and checked the recording sources and how they were obtained.
- 2026-10-10: Re-checked the video status. The embedded videos match the lecture numbering of the official playlist.
- 2026-10-13: Previously combined with Lecture 8 in one article; changed to one article per lecture and rewritten from the handout and the video transcripts.
References
- Techniques Lecture 7 handout, 207_handout.pdf: the main source for this article. The formulas in the four sections, the derivation of the error decomposition, the KDD Cup 2011 numbers, the bagging pocket demonstration, and the four Fun Time questions all come from this handout.
- Techniques Lecture 9 handout, 209_handout.pdf: used only for the blending/learning table at its start, to confirm the answers to the three question marks.
- 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 207u slides, and the further reading list.
- Machine Learning, Fall 2026 course page: the corresponding week.
- Fall 2024 Homework 6 (hw6_red.pdf): the content of Q4 and Q9.
- Fall 2024 Homework 7 (hw7.pdf): the content of Q1 and Q5.
- Chen et al., A linear ensemble of individual and blended models for music rating prediction: the KDD Cup 2011 Track 1 solution cited on page 16 of the handout.
- Breiman, Bagging Predictors: further reading listed on the course page, the original bagging paper.
- Lin, infkernel.pdf: the paper attached to the hint for HW6 Q9.
- Learning from Data textbook website: the textbook the course pages use when mapping lectures to LFD chapters.
- Reading NTU Hsuan-Tien Lin Machine Learning Foundations & Techniques: Course Overview: where this lecture sits in the whole course and the reading routes.