Skip to content

Gradient Boosted Decision Trees: AdaBoost as Gradient Descent on an Error Function | NTU Hsuan-Tien Lin Machine Learning Techniques Lecture 11

Oct 13, 20261 min
TL;DRThe sum of AdaBoost's weights in each round is exactly the sum of the exponential error exp(−ys). From that, this lecture derives that the gₜ found by the base algorithm is an approximate functional gradient direction, and the vote αₜ is the best step size along that direction. Swap the exponential error for squared error and the same derivation becomes 'in each round, run regression on the residuals yₙ − sₙ, then set the step size with one-variable linear regression'; with a weakened C&RT as the base model, that is GBDT.

🌏 中文版

Video status: Videos included. This article is written from the official MOOC handout 211_handout.pdf and transcripts of this lecture's four official videos, with formulas following the handout. The transcripts are machine transcripts made for this article (Whisper), not official captions, and no human has proofread them. The videos are taught in Mandarin; the slides are in English. Each section opens with its official video and the approximate time ranges. Page numbers refer to the number at the lower right of each slide (0/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 11 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 is the last lecture of the second, Combining Predictive Features: Aggregation Models. The previous lecture, Techniques Lecture 10: Random Forests, takes up a single line on that page: bagging of randomized C&RT trees with automatic validation and feature selection. This lecture swaps the outer bagging for boosting, then goes back to a question that Techniques Lecture 8: AdaBoost left unanswered: what is AdaBoost's vote formula, which seemed to come out of nowhere, actually optimizing?

There are five prerequisites:

After reading, you should be able to start from AdaBoost's weight update and derive on your own that gtg_t is a functional gradient direction and αt\alpha_t is the best step size, then carry the same derivation over to squared error, write down the three steps of GBDT, and run a few rounds by hand on a small data set.

The order of the derivation across the lecture:

  1. AdaBoost with decision trees: express the weights through sampling, and weaken the tree.
  2. The sum of weights equals the sum of the exponential error: AdaBoost decreases it in every round.
  3. Fix the step size, find the direction: after a Taylor expansion, the best direction is the hh with the lowest weighted error rate.
  4. Fix the direction, find the step size: set the derivative to 0, and the solution is exactly αt\alpha_t.
  5. Switch to an arbitrary error function: this gives GradientBoost; under squared error the direction is a regression on the residuals, and the step size is a one-variable linear regression.
  6. Use trees as the base model: GBDT.

How a tree works with AdaBoost: pass the weights through sampling, then weaken the tree

YouTube:Gradient Boosted Decision Tree :: AdaBoost Decision Tree @ Machine Learning Techniques (機器學習技法)

(Video 00:18–01:23 reviews random forest, 01:23–07:16 covers how to make a decision tree take weights, 07:23–11:55 covers why the tree has to be weak, 11:55–14:11 is the extreme case of height 1, and Fun Time follows.)

From Random Forest to AdaBoost-DTree

Page 2 of the handout puts two algorithms side by side. On the left is the random forest from the previous lecture; on the right the outer layer is swapped for AdaBoost:

RandomForest(D)AdaBoost-DTree(D)
Step 1 of each roundrequest size-N′N' data D~t\tilde{\mathcal{D}}_t by bootstrapping with D\mathcal{D}reweight data by u(t)\mathbf{u}^{(t)}
Step 2 of each roundgtg_t = Randomized-DTree(D~t\tilde{\mathcal{D}}_t)gtg_t = DTree(D,u(t)\mathcal{D}, \mathbf{u}^{(t)})
Step 3 of each round(none)calculate the vote αt\alpha_t of gtg_t
ReturnGG = Uniform({gt}\{g_t\}), one vote per treeGG = LinearHypo({(gt,αt)}\{(g_t, \alpha_t)\}), a linear combination by votes

Step 2 on the right needs a tree that can take weights, and the handout writes at the bottom of the page need: weighted DTree(D,u(t)\mathcal{D}, \mathbf{u}^{(t)}). The C&RT of Techniques Lecture 9 does not consider a weight on each example, neither when it chooses a branch nor when it decides the constant at a leaf.

Change the data fed in, not the algorithm

Page 3 first states what we expect of a weighted algorithm: it should minimize the weighted EinE_{\text{in}} (possibly with regularization),

Einu(h)=1N∑n=1Nun⋅err(yn,h(xn))E_{\text{in}}^{\mathbf{u}}(h) = \frac{1}{N}\sum_{n=1}^{N} u_n \cdot \text{err}(y_n, h(\mathbf{x}_n))

In the lecture, Lin says there are two routes. The first is to open the algorithm up, find every place where it handles EinE_{\text{in}}, and multiply the weights in. For SVM, for example, the part related to EinE_{\text{in}} is the hinge term, so you multiply each example's term by its weight. This route is a lot of trouble for decision trees: besides the basic steps, a tree has many tricks that different authors added, and you would have to check one by one which of them are related to EinE_{\text{in}}.

The second route is to treat the original algorithm as a black box, leave it completely alone, and work only on the data fed into it. Lin looks back at where the weights came from to explain why this is possible. Techniques Lecture 8 introduced weights starting from bagging, where a weight records how many copies of an example the bootstrap drew; weight 3 means there are 3 copies in the data. In the other direction, when you hold a set of weights u\mathbf{u}, you can sample in proportion to unu_n, and the proportion of each example in the sampled data is then roughly its share of the weights. The handout puts the two side by side:

How the weights are expressedHow to get D~t\tilde{\mathcal{D}}_t
'Weighted' Algorithm in Baggingbootstrap-sampled copiesrequest size-N′N' data by bootstrapping with D\mathcal{D}
A General Randomized Base Algorithmsampling proportional to unu_nrequest size-N′N' data by sampling ∝u\propto \mathbf{u} on D\mathcal{D}

Here are some numbers (an example made up for this article, not from the slides). Five examples have weights (0.1,0.1,0.1,0.1,0.4)(0.1, 0.1, 0.1, 0.1, 0.4), which sum to 0.8, so their probabilities of being drawn are (18,18,18,18,12)(\frac{1}{8}, \frac{1}{8}, \frac{1}{8}, \frac{1}{8}, \frac{1}{2}). Drawing N′=8N' = 8 examples, each of the first four appears 1 time on average and the fifth appears 4 times on average. An unmodified decision tree that sees these 8 examples learns indirectly that the fifth one matters more.

The handout's conclusion is that AdaBoost-DTree is often done via AdaBoost + sampling proportional to u(t)\mathbf{u}^{(t)} + DTree(D~t\tilde{\mathcal{D}}_t), without modifying DTree. Lin puts it plainly in the lecture: we are usually lazy and do not want to modify the decision tree algorithm.

A fully grown tree turns AdaBoost into an autocracy

Page 4 first reviews the vote formula. ϵt\epsilon_t is the weighted error rate of gtg_t (the total weight of the misclassified examples divided by the total weight of all examples):

αt=ln⁡⧫t=ln⁡1−ϵtϵt\alpha_t = \ln \blacklozenge_t = \ln\sqrt{\frac{1-\epsilon_t}{\epsilon_t}}

Then comes a chain of implications. If gtg_t is a fully grown tree trained on all xn\mathbf{x}_n:

  1. As long as all xn\mathbf{x}_n are different, the tree can keep cutting until every example has a leaf to itself, so Ein(gt)=0E_{\text{in}}(g_t) = 0.
  2. With no mistakes at all before weighting, the weighted error is of course also 0: Einu(gt)=0E_{\text{in}}^{\mathbf{u}}(g_t) = 0.
  3. So ϵt=0\epsilon_t = 0.
  4. So αt=ln⁡1/0=∞\alpha_t = \ln\sqrt{1/0} = \infty.

One tree gets infinitely many votes, and nothing the other trees vote can matter. The handout calls this autocracy. In the lecture, Lin explains that this is no longer aggregation, since you only need that one tree; the idea was to combine many trees as random forest does, and the calculation ends up needing just one. The problem comes from two places: all the data was thrown in, and the tree was really allowed to cut all the way down.

So AdaBoost needs a weaker tree, which the handout writes as pruned tree trained on some xn\mathbf{x}_n:

  • pruned: use the usual pruning, or just limit the tree height. Lin adds in the lecture that the pruning methods from Techniques Lecture 9 all work, but since AdaBoost only needs the base model to do roughly well, people often use the simpler option of limiting the height.
  • some: use only part of the data. Sampling already does half of this along the way, because sampling by u(t)\mathbf{u}^{(t)} does not necessarily draw every example.

The conclusion on this page completes the one on the previous page: AdaBoost-DTree is often done via AdaBoost + sampling proportional to u(t)\mathbf{u}^{(t)} + pruned DTree(D~\tilde{\mathcal{D}}).

Pruned down to one level: the decision stump

Which tree is the weakest? Page 5 asks what happens if the height of C&RT is limited to at most 1. The whole tree then has a single branching criterion,

b(x)=argmin⁡decision stumps h(x) ∑c=12∣Dc with h∣⋅impurity(Dc with h)b(\mathbf{x}) = \underset{\text{decision stumps } h(\mathbf{x})}{\operatorname{argmin}} \ \sum_{c=1}^{2} \lvert \mathcal{D}_c \text{ with } h\rvert \cdot \text{impurity}(\mathcal{D}_c \text{ with } h)

that is, make one cut so that the impurity of the two sides, weighted by the amount of data on each, is lowest. If the impurity is binary classification error, this means making one cut, returning +1+1 or −1-1 on each side, and making the fewest classification mistakes, which is exactly the decision stump of Techniques Lecture 8. So the handout says AdaBoost-Stump is a special case of AdaBoost-DTree.

In the lecture, Lin adds an implementation habit that is not on the handout. When the tree is this short, ϵt\epsilon_t is usually not 0, and a decision stump is simple enough to take the weights directly inside the algorithm. So with stumps people usually skip the sampling and use the weights directly; sampling is for general decision trees.

Fun Time: all correct on the sampled data, so what is the vote

Question (page 6): When running AdaBoost-DTree with sampling and getting a decision tree gtg_t such that gtg_t achieves zero error on the sampled data set D~t\tilde{\mathcal{D}}_t. Which of the following is possible?

  1. αt<0\alpha_t < 0
  2. αt=0\alpha_t = 0
  3. αt>0\alpha_t > 0
  4. all of the above

Answer: 4. The handout's explanation: while gtg_t achieves zero error on D~t\tilde{\mathcal{D}}_t, it may not achieve zero weighted error on (D,u(t))(\mathcal{D}, \mathbf{u}^{(t)}), and hence ϵt\epsilon_t can be anything, even at least 12\frac{1}{2}, in which case αt≤0\alpha_t \le 0. αt\alpha_t is computed with the original full data and weights; the sampled data is used only to train the tree.

This article builds one example for each case from the weights (0.1,0.1,0.1,0.1,0.4)(0.1, 0.1, 0.1, 0.1, 0.4) used above. Let the labels of the five examples be (+1,+1,−1,−1,+1)(+1, +1, -1, -1, +1):

The sample happens to contain onlyA tree that is all correct on the sampleMisclassified on the full dataϵt\epsilon_tαt\alpha_t
examples 1, 2, 5always answer +1+1examples 3, 4, weight 0.20.2/0.8=0.250.2/0.8 = 0.25ln⁡3≈0.549\ln\sqrt{3} \approx 0.549
examples 1 to 4+1+1 on the first two, −1-1 on the restexample 5, weight 0.40.4/0.8=0.50.4/0.8 = 0.5ln⁡1=0\ln 1 = 0
examples 3, 4always answer −1-1examples 1, 2, 5, weight 0.60.6/0.8=0.750.6/0.8 = 0.75ln⁡1/3≈−0.549\ln\sqrt{1/3} \approx -0.549

All three signs appear, so choosing option 1, 2, or 3 alone is incomplete.

What AdaBoost minimizes: steepest descent on the exponential error

YouTube:Gradient Boosted Decision Tree :: Optimization of AdaBoost @ Machine Learning Techniques (機器學習技法)

(Video 00:00–05:00 tidies up the weight update, 05:00–09:39 connects the voting score to the margin, 09:39–11:43 is the exponential error, 11:43–17:58 expands it the way gradient descent does, 17:58–21:08 finds the direction, 21:08–26:46 finds the step size, and Fun Time follows.)

Writing the weight update as one formula

The update rule in Techniques Lecture 8 takes two lines: multiply the weight of a misclassified example by ⧫t\blacklozenge_t, and divide the weight of a correct one by ⧫t\blacklozenge_t. Page 7 merges them into one line. In binary classification yny_n and gt(xn)g_t(\mathbf{x}_n) are both ±1\pm 1: when the answer is wrong they have opposite signs and yngt(xn)=−1y_n g_t(\mathbf{x}_n) = -1; when it is right they have the same sign and yngt(xn)=+1y_n g_t(\mathbf{x}_n) = +1. So

un(t+1)=un(t)⋅⧫t −yngt(xn)u_n^{(t+1)} = u_n^{(t)} \cdot \blacklozenge_t^{\,-y_n g_t(\mathbf{x}_n)}

When the answer is wrong the exponent is +1+1, which multiplies by ⧫t\blacklozenge_t; when it is right the exponent is −1-1, which divides by ⧫t\blacklozenge_t. Now use αt=ln⁡⧫t\alpha_t = \ln\blacklozenge_t, that is, ⧫t=exp⁡(αt)\blacklozenge_t = \exp(\alpha_t):

un(t+1)=un(t)⋅exp⁡(−ynαtgt(xn))u_n^{(t+1)} = u_n^{(t)} \cdot \exp\big(-y_n \alpha_t g_t(\mathbf{x}_n)\big)

Every round multiplies by an exponential. Starting from un(1)=1Nu_n^{(1)} = \frac{1}{N} and multiplying all the way to the end of round TT, the exponents of the product can move inside a single exp and become a sum:

un(T+1)=un(1)⋅∏t=1Texp⁡(−ynαtgt(xn))=1N⋅exp⁡(−yn∑t=1Tαtgt(xn))u_n^{(T+1)} = u_n^{(1)} \cdot \prod_{t=1}^{T}\exp\big(-y_n\alpha_t g_t(\mathbf{x}_n)\big) = \frac{1}{N}\cdot\exp\Big(-y_n \sum_{t=1}^{T}\alpha_t g_t(\mathbf{x}_n)\Big)

The ∑tαtgt(x)\sum_t \alpha_t g_t(\mathbf{x}) inside the exp looks familiar: what AdaBoost finally returns is G(x)=sign(∑t=1Tαtgt(x))G(\mathbf{x}) = \text{sign}\big(\sum_{t=1}^{T}\alpha_t g_t(\mathbf{x})\big), and this is the quantity before the sign is taken. The handout calls it the voting score of {gt}\{g_t\} on x\mathbf{x}. The conclusion of this page is

un(T+1)∝exp⁡(−yn⋅(voting score on xn))u_n^{(T+1)} \propto \exp\big(-y_n \cdot (\text{voting score on } \mathbf{x}_n)\big)

The final weight of each example is determined only by its label and the voting score it receives.

The voting score is an unnormalized margin

Page 8 returns to the view from Techniques Lecture 7: linear blending is LinModel + hypotheses as transform. The handout originally listed a third item, constraints, which is crossed out on the slide. In the lecture, Lin explains that votes should in principle not be negative, which would call for a condition, but as said before it does no harm to leave it out; a negative vote just uses that gtg_t's opinion in reverse.

In this view, take gt(xn)g_t(\mathbf{x}_n) as the tt-th transformed feature ϕt(xn)\phi_t(\mathbf{x}_n) and αt\alpha_t as the weight wtw_t on that feature, and the voting score is w⊤ϕ(xn)\mathbf{w}^\top\boldsymbol{\phi}(\mathbf{x}_n). The margin of hard-margin SVM is

margin=yn(w⊤ϕ(xn)+b)∥w∥\text{margin} = \frac{y_n\big(\mathbf{w}^\top\boldsymbol{\phi}(\mathbf{x}_n) + b\big)}{\lVert\mathbf{w}\rVert}

Comparing the two, yn⋅(voting score)y_n \cdot (\text{voting score}) is a signed & unnormalized margin. Lin points out two differences from SVM in the lecture: there is no division by ∥w∥\lVert\mathbf{w}\rVert, and there is no bb. Multiplying by yny_n brings in the information about being on the correct side or the wrong side.

We want this margin to be positive (classified correctly) and large (far from the boundary). The handout continues with three lines of equivalences:

  • want yn⋅(voting score)y_n \cdot (\text{voting score}) positive and large
  • which is the same as wanting exp⁡(−yn⋅(voting score))\exp(-y_n \cdot (\text{voting score})) small
  • which is the same as wanting un(T+1)u_n^{(T+1)} small

The last step uses the proportionality from page 7. The handout then states the claim of this section: AdaBoost decreases ∑n=1Nun(t)\sum_{n=1}^{N} u_n^{(t)} as the rounds go on. Lin's extension in the lecture is that AdaBoost, while it runs, keeps trying to make the margin of every point more positive and larger, so it can achieve a large-margin effect.

Exponential error: a convex upper bound of the 0/1 error

Add up the final weights of all the examples (page 9):

∑n=1Nun(T+1)=1N∑n=1Nexp⁡(−yn∑t=1Tαtgt(xn))\sum_{n=1}^{N} u_n^{(T+1)} = \frac{1}{N}\sum_{n=1}^{N}\exp\Big(-y_n\sum_{t=1}^{T}\alpha_t g_t(\mathbf{x}_n)\Big)

Write the linear score as s=∑t=1Tαtgt(xn)s = \sum_{t=1}^{T}\alpha_t g_t(\mathbf{x}_n), and every term on the right is a function of (s,y)(s, y). The handout places it next to the 0/1 error:

err0/1(s,y)=[ ⁣[ ys≤0 ] ⁣],err^ADA(s,y)=exp⁡(−ys)\text{err}_{0/1}(s, y) = [\![\, ys \le 0 \,]\!], \qquad \widehat{\text{err}}_{\text{ADA}}(s, y) = \exp(-ys)

The figure on page 9 has ysys on the horizontal axis. The black 0/1 error is a step: 1 when ys≤0ys \le 0 and 0 when ys>0ys > 0. The purple exp⁡(−ys)\exp(-ys) is a curve that falls to the right and passes through (0,1)(0, 1); the whole curve is never below the step, and the two touch only at the point ys=0ys = 0. Values at a few points (the numbers are computed by this article):

ysys−2-2−1-1001122
0/1 error11100
exp⁡(−ys)\exp(-ys)7.392.7210.370.14

When ys≤0ys \le 0 we have exp⁡(−ys)≥1\exp(-ys) \ge 1, and when ys>0ys > 0 we have exp⁡(−ys)>0\exp(-ys) > 0, so it is an upper bound of the 0/1 error; it is also convex. The handout calls err^ADA\widehat{\text{err}}_{\text{ADA}} the exponential error measure and positions it as an algorithmic error measure: doing well on the 0/1 error indirectly through a convex upper bound. Lin reminds us in the lecture that we have met this move again and again; SVM's hinge error and logistic regression's scaled cross-entropy are both upper bounds of the 0/1 error.

So "AdaBoost decreases the sum of weights" can be rewritten as "AdaBoost minimizes the exponential error to some extent"; the handout's wording is somewhat minimizes. The next two subsections prove this statement and make clear how the minimization happens.

Treating a function as a direction

Page 10 first reviews gradient descent from Foundations Lecture 10. At step tt we stand at wt\mathbf{w}_t and want to take a small step η\eta along some unit direction v\mathbf{v}. A Taylor expansion writes the nearby EinE_{\text{in}} as a first-order expression:

min⁡∥v∥=1Ein(wt+ηv)≈Ein(wt)⏟known+η⏟given positive v⊤∇Ein(wt)⏟known\min_{\lVert\mathbf{v}\rVert = 1} E_{\text{in}}(\mathbf{w}_t + \eta\mathbf{v}) \approx \underbrace{E_{\text{in}}(\mathbf{w}_t)}_{\text{known}} + \underbrace{\eta}_{\text{given positive}} \ \mathbf{v}^\top\underbrace{\nabla E_{\text{in}}(\mathbf{w}_t)}_{\text{known}}

Lin's review in the lecture: under the length constraint, the direction that minimizes this first-order expression is the negative gradient, and taking a small step η\eta that way lowers the error a little.

Now follow the same pattern. When AdaBoost reaches round tt it already holds g1,…,gt−1g_1, \dots, g_{t-1} and α1,…,αt−1\alpha_1, \dots, \alpha_{t-1}, and that is where we currently stand. The next step adds a new gtg_t and αt\alpha_t; before they are decided, call them hh and η\eta. hh plays the role of the direction v\mathbf{v}, except that it is a function.

In the lecture, Lin asks the question on the students' behalf: the direction used to be a vector, so how can we now be looking for a function? The reply is that functions and vectors are not that different. Give a vector an index (which entry) and it returns the value of that entry; give a function an x\mathbf{x} and it returns the function value. Only the kind of index differs, and everything else is done as before.

The problem to solve in round tt is

min⁡h E^ADA=1N∑n=1Nexp⁡(−yn(∑τ=1t−1ατgτ(xn)+ηh(xn)))\min_{h}\ \widehat{E}_{\text{ADA}} = \frac{1}{N}\sum_{n=1}^{N}\exp\Big(-y_n\Big(\sum_{\tau=1}^{t-1}\alpha_\tau g_\tau(\mathbf{x}_n) + \eta h(\mathbf{x}_n)\Big)\Big)

Step one: collect the known part into the weights. The sum in the exponent splits into a product of two exps. The first half, 1Nexp⁡(−yn∑τ=1t−1ατgτ(xn))\frac{1}{N}\exp\big(-y_n\sum_{\tau=1}^{t-1}\alpha_\tau g_\tau(\mathbf{x}_n)\big), is exactly un(t)u_n^{(t)} by the product formula above (with TT replaced by t−1t-1):

E^ADA=∑n=1Nun(t)exp⁡(−ynηh(xn))\widehat{E}_{\text{ADA}} = \sum_{n=1}^{N} u_n^{(t)}\exp\big(-y_n\eta h(\mathbf{x}_n)\big)

Step two: Taylor expansion. When η\eta is small, exp⁡(z)≈1+z\exp(z) \approx 1 + z near the origin. Take z=−ynηh(xn)z = -y_n\eta h(\mathbf{x}_n):

E^ADA≈∑n=1Nun(t)(1−ynηh(xn))=∑n=1Nun(t)−η∑n=1Nun(t)ynh(xn)\widehat{E}_{\text{ADA}} \approx \sum_{n=1}^{N} u_n^{(t)}\big(1 - y_n\eta h(\mathbf{x}_n)\big) = \sum_{n=1}^{N} u_n^{(t)} - \eta\sum_{n=1}^{N} u_n^{(t)} y_n h(\mathbf{x}_n)

The form matches the gradient descent line exactly: the first term is the current error, a known constant; the second is η\eta times a quantity that depends on the direction. η\eta is positive, so a good hh should make

∑n=1Nun(t)(−ynh(xn))\sum_{n=1}^{N} u_n^{(t)}\big(-y_n h(\mathbf{x}_n)\big)

as small as possible.

An addition in this article: gradient descent has to impose ∥v∥=1\lVert\mathbf{v}\rVert = 1, since otherwise a longer direction gives a lower value of the first-order expression and there is no minimum. No extra constraint is added here because a binary classification hh only outputs ±1\pm 1, so its magnitude is fixed to begin with. The issue only surfaces in the section on switching the error function, where hh becomes real-valued, and the handout handles it there with a penalty term.

Finding the direction: the base algorithm has been doing it all along

Page 11 rearranges the quantity above into something recognizable. In binary classification yny_n and h(xn)h(\mathbf{x}_n) are both ±1\pm 1, so −ynh(xn)-y_n h(\mathbf{x}_n) is −1-1 when the answer is right and +1+1 when it is wrong. Pull a −1-1 out of every term, and what remains is 0 for right and 2 for wrong:

∑n=1Nun(t)(−ynh(xn))=−∑n=1Nun(t)+∑n=1Nun(t)⋅2 [ ⁣[ yn≠h(xn) ] ⁣]=−∑n=1Nun(t)+2Einu(t)(h)⋅N\sum_{n=1}^{N} u_n^{(t)}\big(-y_n h(\mathbf{x}_n)\big) = -\sum_{n=1}^{N} u_n^{(t)} + \sum_{n=1}^{N} u_n^{(t)}\cdot 2\,[\![\, y_n \ne h(\mathbf{x}_n) \,]\!] = -\sum_{n=1}^{N} u_n^{(t)} + 2E_{\text{in}}^{\mathbf{u}^{(t)}}(h)\cdot N

The last equality uses Einu(t)(h)=1N∑nun(t)[ ⁣[ yn≠h(xn) ] ⁣]E_{\text{in}}^{\mathbf{u}^{(t)}}(h) = \frac{1}{N}\sum_n u_n^{(t)}[\![\, y_n \ne h(\mathbf{x}_n) \,]\!]; the definition contains 1N\frac{1}{N}, so we multiply NN back. The first term does not depend on hh, and therefore

finding good hh (function direction) ⟺\Longleftrightarrow minimize Einu(t)(h)E_{\text{in}}^{\mathbf{u}^{(t)}}(h)

Who minimizes the weighted EinuE_{\text{in}}^{\mathbf{u}}? The base algorithm A\mathcal{A} in AdaBoost. Techniques Lecture 8 asked only one thing of it, to drive the weighted 0/1 error down once it receives the weights; we now know that the gtg_t it hands back is at the same time a good direction in this approximate optimization problem. Lin's comment in the lecture is that the math is a little magical.

Finding the step size: the solution is α

Once the direction is set, gradient descent would take a fixed small step and then look for the next direction. Page 12 asks: since gtg_t is already fixed, why not solve directly

min⁡η E^ADA=∑n=1Nun(t)exp⁡(−ynηgt(xn))\min_{\eta}\ \widehat{E}_{\text{ADA}} = \sum_{n=1}^{N} u_n^{(t)}\exp\big(-y_n\eta g_t(\mathbf{x}_n)\big)

The motivation Lin gives in the lecture is that this direction was computed by another algorithm, and computing it once is not cheap, so it is worth taking a bigger step. The handout says the optimal ηt\eta_t solved this way is somewhat greedily faster than a fixed small η\eta, and that this is called steepest descent in optimization. Lin explains what greedily means: it only guarantees that this round looks faster, with no guarantee that it is faster in the long run.

Note that this step needs no Taylor expansion; with gtg_t fixed it can be computed directly. There are only two kinds of terms in the summation:

  • correct (yn=gt(xn)y_n = g_t(\mathbf{x}_n)): un(t)exp⁡(−η)u_n^{(t)}\exp(-\eta)
  • incorrect (yn≠gt(xn)y_n \ne g_t(\mathbf{x}_n)): un(t)exp⁡(+η)u_n^{(t)}\exp(+\eta)

The total weight of the incorrect examples is ϵt∑nun(t)\epsilon_t\sum_n u_n^{(t)} and that of the correct ones is (1−ϵt)∑nun(t)(1-\epsilon_t)\sum_n u_n^{(t)}; this is the definition of ϵt\epsilon_t. Factor out the total weight:

E^ADA=(∑n=1Nun(t))⋅((1−ϵt)exp⁡(−η)+ϵtexp⁡(+η))\widehat{E}_{\text{ADA}} = \Big(\sum_{n=1}^{N} u_n^{(t)}\Big)\cdot\big((1-\epsilon_t)\exp(-\eta) + \epsilon_t\exp(+\eta)\big)

This is a differentiable function of the single variable η\eta. Differentiate with respect to η\eta and set the result to 0:

∂E^ADA∂η=(∑n=1Nun(t))⋅(−(1−ϵt)exp⁡(−η)+ϵtexp⁡(+η))=0\frac{\partial\widehat{E}_{\text{ADA}}}{\partial\eta} = \Big(\sum_{n=1}^{N} u_n^{(t)}\Big)\cdot\big(-(1-\epsilon_t)\exp(-\eta) + \epsilon_t\exp(+\eta)\big) = 0

The total weight is positive, so the bracket must be 0: ϵtexp⁡(η)=(1−ϵt)exp⁡(−η)\epsilon_t\exp(\eta) = (1-\epsilon_t)\exp(-\eta). Multiply both sides by exp⁡(η)\exp(\eta) and divide by ϵt\epsilon_t to get exp⁡(2η)=1−ϵtϵt\exp(2\eta) = \frac{1-\epsilon_t}{\epsilon_t}, then take the logarithm and divide by 2:

ηt=12ln⁡1−ϵtϵt=ln⁡1−ϵtϵt=αt\eta_t = \frac{1}{2}\ln\frac{1-\epsilon_t}{\epsilon_t} = \ln\sqrt{\frac{1-\epsilon_t}{\epsilon_t}} = \alpha_t

An addition in this article: the second derivative is (∑nun(t))((1−ϵt)exp⁡(−η)+ϵtexp⁡(η))>0\big(\sum_n u_n^{(t)}\big)\big((1-\epsilon_t)\exp(-\eta) + \epsilon_t\exp(\eta)\big) > 0, so this point is a minimum.

Techniques Lecture 8 explained αt\alpha_t as "the better gtg_t performs, the more votes it gets"; Lin says in the lecture that we now see it was quietly carrying out an optimization. The handout sums up the whole section in one line: AdaBoost is steepest descent with approximate functional gradient. Functional gradient refers to doing something like gradient descent in the world of functions; approximate is because finding the direction used the Taylor approximation.

This article adds one more step and turns the handout's claim into numbers. Substitute η=αt\eta = \alpha_t back in. With exp⁡(−αt)=ϵt/(1−ϵt)\exp(-\alpha_t) = \sqrt{\epsilon_t/(1-\epsilon_t)} and exp⁡(αt)=(1−ϵt)/ϵt\exp(\alpha_t) = \sqrt{(1-\epsilon_t)/\epsilon_t}, each of the two terms equals ϵt(1−ϵt)\sqrt{\epsilon_t(1-\epsilon_t)}:

∑n=1Nun(t+1)=(∑n=1Nun(t))⋅2ϵt(1−ϵt)\sum_{n=1}^{N} u_n^{(t+1)} = \Big(\sum_{n=1}^{N} u_n^{(t)}\Big)\cdot 2\sqrt{\epsilon_t(1-\epsilon_t)}

The left side can be written as the next round's sum of weights because substituting η=αt\eta = \alpha_t into un(t)exp⁡(−ynηgt(xn))u_n^{(t)}\exp(-y_n\eta g_t(\mathbf{x}_n)) gives un(t+1)u_n^{(t+1)}. 2ϵt(1−ϵt)2\sqrt{\epsilon_t(1-\epsilon_t)} equals 1 when ϵt=12\epsilon_t = \frac{1}{2} and is less than 1 otherwise. So as long as the base algorithm does a little better than random guessing in every round, the sum of weights (that is, the exponential error) really does go down every round. This is the precise version of the claim on page 8.

Numerical example: three rounds of AdaBoost-Stump on five points

The following is an example made up for this article, not from the slides, used to put a number on every formula in this section. The data are five points in one dimension:

nn12345
xnx_n12345
yny_n+1+1+1+1−1-1−1-1+1+1

The base algorithm is the decision stump: choose a threshold and a direction that give the lowest weighted error rate (answering the same sign on the whole line is also allowed). The initial weights are un(1)=15u_n^{(1)} = \frac{1}{5}, with sum U1=1U_1 = 1.

Round 1. The best stump is g1(x)=sign(2.5−x)g_1(x) = \text{sign}(2.5 - x), which outputs (+,+,−,−,−)(+,+,-,-,-) and is wrong only on example 5. ϵ1=0.2\epsilon_1 = 0.2, ⧫1=0.8/0.2=2\blacklozenge_1 = \sqrt{0.8/0.2} = 2, α1=ln⁡2≈0.693\alpha_1 = \ln 2 \approx 0.693.

Look first at the function from the step-size subsection. In this round E^ADA(η)=0.8exp⁡(−η)+0.2exp⁡(η)\widehat{E}_{\text{ADA}}(\eta) = 0.8\exp(-\eta) + 0.2\exp(\eta):

η\etaE^ADA(η)\widehat{E}_{\text{ADA}}(\eta)Note
0011no step yet, equal to U1U_1
0.10.10.94490.9449a fixed small step; the Taylor approximation gives 1−0.1×0.6=0.941 - 0.1\times 0.6 = 0.94
ln⁡2≈0.693\ln 2 \approx 0.6930.4+0.4=0.80.4 + 0.4 = 0.8the steepest descent step size
2ln⁡2≈1.3862\ln 2 \approx 1.3860.2+0.8=10.2 + 0.8 = 1overshoots and returns to the original height

The 0.60.6 in the Taylor approximation row is ∑nun(1)yng1(xn)=0.8−0.2\sum_n u_n^{(1)} y_n g_1(x_n) = 0.8 - 0.2. The lowest point is at η=α1\eta = \alpha_1, with value 0.8=1×20.2×0.80.8 = 1 \times 2\sqrt{0.2\times 0.8}, in agreement with the formula. Update the weights: the misclassified example 5 becomes 0.2×2=0.40.2\times 2 = 0.4, the other four become 0.2/2=0.10.2/2 = 0.1, and the sum is U2=0.8U_2 = 0.8.

Round 2. The weights are (0.1,0.1,0.1,0.1,0.4)(0.1, 0.1, 0.1, 0.1, 0.4). The previous round's g1g_1 now has weighted error rate 0.4/0.8=0.50.4/0.8 = 0.5, the same as random guessing, which is the design explained in Techniques Lecture 8. Two stumps tie for best in this round: sign(x−4.5)\text{sign}(x - 4.5) is wrong on examples 1 and 2, and the one that answers +1+1 on the whole line is wrong on examples 3 and 4. Both have misclassified weight 0.20.2, and every other cut is worse. Here we take g2(x)=sign(x−4.5)g_2(x) = \text{sign}(x - 4.5), which outputs (−,−,−,−,+)(-,-,-,-,+) (choosing the other one would change the numbers that follow, but two things still hold: the sum of weights equals the average exponential error, and it falls each round by the ratio 2ϵt(1−ϵt)2\sqrt{\epsilon_t(1-\epsilon_t)}). ϵ2=0.2/0.8=0.25\epsilon_2 = 0.2/0.8 = 0.25, ⧫2=3\blacklozenge_2 = \sqrt{3}, α2=ln⁡3≈0.549\alpha_2 = \ln\sqrt{3} \approx 0.549. The new weights: examples 1 and 2 are 0.13≈0.1730.1\sqrt{3} \approx 0.173, examples 3 and 4 are 0.1/3≈0.0580.1/\sqrt{3} \approx 0.058, and example 5 is 0.4/3≈0.2310.4/\sqrt{3} \approx 0.231. The sum is U3≈0.693=0.8×20.25×0.75U_3 \approx 0.693 = 0.8\times 2\sqrt{0.25\times 0.75}.

Round 3. The best stump is g3g_3, which answers +1+1 on the whole line and is wrong on examples 3 and 4. ϵ3=0.115/0.693=16\epsilon_3 = 0.115/0.693 = \frac{1}{6}, ⧫3=5\blacklozenge_3 = \sqrt{5}, α3=ln⁡5≈0.805\alpha_3 = \ln\sqrt{5} \approx 0.805. The sum is U4≈0.516=0.693×216×56U_4 \approx 0.516 = 0.693\times 2\sqrt{\frac{1}{6}\times\frac{5}{6}}.

After three rounds, the voting score of each example, sn=∑tαtgt(xn)s_n = \sum_t \alpha_t g_t(x_n):

nnsns_n (after round 1)sns_n (after round 2)sns_n (after round 3)ynsny_n s_n after round 3
1, 20.6930.6930.1440.1440.9490.9490.9490.949
3, 4−0.693-0.693−1.242-1.242−0.438-0.4380.4380.438
5−0.693-0.693−0.144-0.1440.6610.6610.6610.661
InitialAfter round 1After round 2After round 3
Sum of weights Ut+1U_{t+1}110.80.80.6930.6930.5160.516
1N∑nexp⁡(−ynsn)\frac{1}{N}\sum_n\exp(-y_n s_n)110.80.80.6930.6930.5160.516
Ein(G)E_{\text{in}}(G) (0/1)no GG yet0.20.20.20.200

What this result means. The second row is identical to the first, and that is the equation on page 9: the sum of weights is the average exponential error. It falls every round, by the ratio 2ϵt(1−ϵt)2\sqrt{\epsilon_t(1-\epsilon_t)}, which is 0.80.8, 0.8660.866, and 0.7450.745 in turn. The 0/1 error stays pinned below the exponential error throughout; in round 2 it does not move (example 5 is still wrong), yet the exponential error falls all the same, because what AdaBoost optimizes is the upper bound. After round 3 all five ynsny_n s_n are positive: three stumps that each make mistakes combine to classify all the data correctly.

Fun Time: differentiating with respect to η

Question (page 13): With E^ADA=(∑n=1Nun(t))⋅((1−ϵt)exp⁡(−η)+ϵtexp⁡(+η))\widehat{E}_{\text{ADA}} = \big(\sum_{n=1}^{N} u_n^{(t)}\big)\cdot\big((1-\epsilon_t)\exp(-\eta) + \epsilon_t\exp(+\eta)\big), which of the following is ∂E^ADA∂η\frac{\partial\widehat{E}_{\text{ADA}}}{\partial\eta} that can be used for solving the optimal ηt\eta_t? All four options begin with (∑n=1Nun(t))\big(\sum_{n=1}^{N} u_n^{(t)}\big) and differ in the bracket that follows:

  1. (+(1−ϵt)exp⁡(−η)+ϵtexp⁡(+η))\big(+(1-\epsilon_t)\exp(-\eta) + \epsilon_t\exp(+\eta)\big)
  2. (+(1−ϵt)exp⁡(−η)−ϵtexp⁡(+η))\big(+(1-\epsilon_t)\exp(-\eta) - \epsilon_t\exp(+\eta)\big)
  3. (−(1−ϵt)exp⁡(−η)+ϵtexp⁡(+η))\big(-(1-\epsilon_t)\exp(-\eta) + \epsilon_t\exp(+\eta)\big)
  4. (−(1−ϵt)exp⁡(−η)−ϵtexp⁡(+η))\big(-(1-\epsilon_t)\exp(-\eta) - \epsilon_t\exp(+\eta)\big)

Answer: 3. Differentiating exp⁡(−η)\exp(-\eta) with respect to η\eta brings out a −1-1, differentiating exp⁡(+η)\exp(+\eta) brings out a +1+1, and the other coefficients stay the same. These are also the two sentences Lin says in the lecture.

Where the other options go wrong: option 1 is identical to the original expression, as if nothing had been differentiated (it is in fact the second derivative). Option 4 treats both terms as gaining a minus sign. Option 2 is the correct answer multiplied through by −1-1; setting it to 0 gives the same ηt\eta_t, but it is not the partial derivative the question asks for. Check with round 1 of the example: with ϵ1=0.2\epsilon_1 = 0.2 and η=ln⁡2\eta = \ln 2, the bracket of option 3 is −0.8×12+0.2×2=0-0.8\times\frac{1}{2} + 0.2\times 2 = 0, exactly the lowest point.

Switching the error function: under squared error, every round fits the residuals

YouTube:Gradient Boosted Decision Tree :: Gradient Boosting @ Machine Learning Techniques (機器學習技法)

(Video 00:00–02:45 generalizes from AdaBoost to GradientBoost, 02:45–07:24 is the Taylor expansion under squared error, 07:24–12:09 adds the penalty term and arrives at residuals, 12:09–15:00 decides the step size, 15:00–17:45 assembles GBDT, and Fun Time follows.)

From AdaBoost to GradientBoost

The conclusion of the optimization view can be written as a two-level optimization problem (page 14):

AdaBoost:min⁡ηmin⁡h 1N∑n=1Nexp⁡(−yn(∑τ=1t−1ατgτ(xn)+ηh(xn)))\text{AdaBoost:}\quad \min_{\eta}\min_{h}\ \frac{1}{N}\sum_{n=1}^{N}\exp\Big(-y_n\Big(\sum_{\tau=1}^{t-1}\alpha_\tau g_\tau(\mathbf{x}_n) + \eta h(\mathbf{x}_n)\Big)\Big)

where hh is a binary-output hypothesis. Since what each round does is "optimize over hh first, then over η\eta", the same can be done with exp swapped for another error function:

GradientBoost:min⁡ηmin⁡h 1N∑n=1Nerr(∑τ=1t−1ατgτ(xn)+ηh(xn), yn)\text{GradientBoost:}\quad \min_{\eta}\min_{h}\ \frac{1}{N}\sum_{n=1}^{N}\text{err}\Big(\sum_{\tau=1}^{t-1}\alpha_\tau g_\tau(\mathbf{x}_n) + \eta h(\mathbf{x}_n),\ y_n\Big)

Here hh can be whichever hypothesis you like, and the handout notes that it is usually a real-output one. The handout's positioning is that GradientBoost allows extension to different err, for regression, soft classification, and so on. Lin's examples in the lecture: use cross-entropy if you care about the kind of problem logistic regression solves, and squared error for regression. Lin also notes that because the method belongs to the gradient descent family, the error function has to be smooth enough.

This lecture derives only the regression version.

The Taylor expansion under squared error

Page 15 takes err(s,y)=(s−y)2\text{err}(s, y) = (s - y)^2 and writes the score accumulated so far as

sn=∑τ=1t−1ατgτ(xn)s_n = \sum_{\tau=1}^{t-1}\alpha_\tau g_\tau(\mathbf{x}_n)

In the lecture, Lin explains that this is now regression, so sns_n can no longer quite be called a voting score; it is simply the value accumulated with weights over the earlier rounds. Each example starts from sns_n and moves by ηh(xn)\eta h(\mathbf{x}_n). Take a first-order Taylor expansion of err in its first argument around sns_n:

err(sn+ηh(xn),yn)≈err(sn,yn)+ηh(xn)⋅∂ err(s,yn)∂s∣s=sn\text{err}\big(s_n + \eta h(\mathbf{x}_n), y_n\big) \approx \text{err}(s_n, y_n) + \eta h(\mathbf{x}_n)\cdot\frac{\partial\,\text{err}(s, y_n)}{\partial s}\bigg|_{s = s_n}

Lin stresses in the lecture that ss is a variable and sns_n is a number already computed; sns_n is substituted only after the partial derivative is taken. The derivative of (s−yn)2(s - y_n)^2 with respect to ss is 2(s−yn)2(s - y_n), and substituting s=sns = s_n gives 2(sn−yn)2(s_n - y_n). The first term does not depend on hh and is a constant:

min⁡h 1N∑n=1Nerr(sn+ηh(xn),yn)≈min⁡h constants+ηN∑n=1Nh(xn)⋅2(sn−yn)\min_{h}\ \frac{1}{N}\sum_{n=1}^{N}\text{err}\big(s_n + \eta h(\mathbf{x}_n), y_n\big) \approx \min_{h}\ \text{constants} + \frac{\eta}{N}\sum_{n=1}^{N} h(\mathbf{x}_n)\cdot 2(s_n - y_n)

We want the last term as small as possible. Lin walks the students through it in the lecture: if sn−yns_n - y_n is positive, give a negative h(xn)h(\mathbf{x}_n); if it is negative, give a positive one, so the product is always negative. And the magnitude? 100 is better than 1, 1000 is better than 100, and bigger is always better. So the handout writes this meaningless solution at the bottom of the page: with no constraint on hh,

h(xn)=−∞⋅(sn−yn)h(\mathbf{x}_n) = -\infty\cdot(s_n - y_n)

An addition in this article: squared error can in fact be expanded directly, (sn+ηh−yn)2=(sn−yn)2+2ηh(sn−yn)+η2h2(s_n + \eta h - y_n)^2 = (s_n - y_n)^2 + 2\eta h(s_n - y_n) + \eta^2 h^2. What the first-order Taylor expansion throws away is exactly the final η2h2\eta^2 h^2, which would have stopped hh from growing without bound. The penalty term the handout adds next does something similar.

Adding a penalty term: the direction is a regression on the residuals

Page 16 deals with this run to infinity. The first observation: the magnitude of hh does not matter, because η\eta will be optimized next and is in charge of the step size. Gradient descent imposed ∥v∥=1\lVert\mathbf{v}\rVert = 1; Lin says in the lecture that the length of hh could be constrained here too, but that means solving a constrained optimization problem, which is a nuisance. Instead use the move from regularization in Foundations Lecture 14: turn the constraint into a penalty term and put it into the expression being minimized. The larger hh is, the heavier the penalty:

min⁡h constants+ηN∑n=1N(2h(xn)(sn−yn)+(h(xn))2)\min_{h}\ \text{constants} + \frac{\eta}{N}\sum_{n=1}^{N}\Big(2h(\mathbf{x}_n)(s_n - y_n) + \big(h(\mathbf{x}_n)\big)^2\Big)

h2h^2 is chosen as the penalty in order to complete the square. A squared term plus "twice hh times some quantity" can be made into a perfect square:

2h(xn)(sn−yn)+(h(xn))2=(h(xn)+(sn−yn))2−(sn−yn)2=(h(xn)−(yn−sn))2−(yn−sn)22h(\mathbf{x}_n)(s_n - y_n) + \big(h(\mathbf{x}_n)\big)^2 = \big(h(\mathbf{x}_n) + (s_n - y_n)\big)^2 - (s_n - y_n)^2 = \big(h(\mathbf{x}_n) - (y_n - s_n)\big)^2 - (y_n - s_n)^2

The (yn−sn)2(y_n - s_n)^2 subtracted at the end depends only on the current score and the label, so it is a constant. The problem becomes

min⁡h constants+ηN∑n=1N(constant+(h(xn)−(yn−sn))2)\min_{h}\ \text{constants} + \frac{\eta}{N}\sum_{n=1}^{N}\Big(\text{constant} + \big(h(\mathbf{x}_n) - (y_n - s_n)\big)^2\Big)

The only part that depends on hh is ∑n(h(xn)−(yn−sn))2\sum_n\big(h(\mathbf{x}_n) - (y_n - s_n)\big)^2: we want h(xn)h(\mathbf{x}_n) as close as possible to yn−sny_n - s_n in the squared-error sense. This is a regression problem, with data {(xn, yn−sn)}\{(\mathbf{x}_n,\ y_n - s_n)\}.

yn−sny_n - s_n is the target value minus the score achieved so far, and the handout calls it the residual. In the lecture, Lin calls it the remainder and gives this analogy: you want 100 points, you have reached 90, and 10 points are still not done. The handout's conclusion:

GradientBoost for regression: find gt=hg_t = h by regression with residuals

Lin contrasts this with AdaBoost in the lecture: in each round AdaBoost hands the base algorithm a new set of weights, while GradientBoost for regression hands the base algorithm a new set of target values (the residuals).

An addition in this article: the relation between the residual and the gradient is direct, yn−sn=−12⋅∂ err∂s∣s=sny_n - s_n = -\frac{1}{2}\cdot\frac{\partial\,\text{err}}{\partial s}\big|_{s = s_n}. Running regression on the residuals means finding a function that stays as close as possible to the negative gradient at every xn\mathbf{x}_n, and this is where the gradient in the name comes from.

The step size is a one-variable linear regression

After finding gt=hg_t = h, page 17 fixes it and optimizes over η\eta only (the min⁡h\min_h on the slide is crossed out):

min⁡η 1N∑n=1N(sn+ηgt(xn)−yn)2=1N∑n=1N((yn−sn)−ηgt(xn))2\min_{\eta}\ \frac{1}{N}\sum_{n=1}^{N}\big(s_n + \eta g_t(\mathbf{x}_n) - y_n\big)^2 = \frac{1}{N}\sum_{n=1}^{N}\big((y_n - s_n) - \eta g_t(\mathbf{x}_n)\big)^2

The equality only flips the sign of every term inside the bracket, which does not affect the square. The form on the right is familiar: yn−sny_n - s_n is the residual again, gt(xn)g_t(\mathbf{x}_n) is a known number, and we look for a coefficient η\eta that brings ηgt(xn)\eta g_t(\mathbf{x}_n) close to the residual. This is linear regression with only one variable, where the input is the gtg_t-transformed gt(xn)g_t(\mathbf{x}_n) and the output is the residual. Lin makes a point of saying in the lecture that there is no constant term x0x_0 here, so there really is just one variable. It also differs from the regression in the previous step: that one has to be solved by the base algorithm A\mathcal{A}, and this one has a closed-form solution.

Let us derive the formula ourselves. Differentiate with respect to η\eta and set the result to 0:

ddη∑n=1N((yn−sn)−ηgt(xn))2=−2∑n=1Ngt(xn)((yn−sn)−ηgt(xn))=0\frac{d}{d\eta}\sum_{n=1}^{N}\big((y_n - s_n) - \eta g_t(\mathbf{x}_n)\big)^2 = -2\sum_{n=1}^{N} g_t(\mathbf{x}_n)\big((y_n - s_n) - \eta g_t(\mathbf{x}_n)\big) = 0

Expanding gives ∑ngt(xn)(yn−sn)=η∑ngt2(xn)\sum_n g_t(\mathbf{x}_n)(y_n - s_n) = \eta\sum_n g_t^2(\mathbf{x}_n), so

αt=ηopt=∑n=1Ngt(xn)(yn−sn)∑n=1Ngt2(xn)\alpha_t = \eta_{\text{opt}} = \frac{\sum_{n=1}^{N} g_t(\mathbf{x}_n)(y_n - s_n)}{\sum_{n=1}^{N} g_t^2(\mathbf{x}_n)}

The handout's conclusion: in GradientBoost for regression, αt\alpha_t is the optimal η\eta, computed by gtg_t-transformed linear regression.

Putting everything together: GBDT

Page 18 puts the two steps inside a loop, which gives the Gradient Boosted Decision Tree (GBDT):

  1. Initialize: s1=s2=⋯=sN=0s_1 = s_2 = \dots = s_N = 0.
  2. For t=1,2,…,Tt = 1, 2, \dots, T:
    1. Obtain gtg_t by the regression algorithm A\mathcal{A} (which minimizes squared error) on {(xn, yn−sn)}\{(\mathbf{x}_n,\ y_n - s_n)\}. The handout asks here: how about sampled and pruned C&RT?
    2. Compute αt=OneVarLinearRegression({(gt(xn), yn−sn)})\alpha_t = \text{OneVarLinearRegression}\big(\{(g_t(\mathbf{x}_n),\ y_n - s_n)\}\big).
    3. Update sn←sn+αtgt(xn)s_n \leftarrow s_n + \alpha_t g_t(\mathbf{x}_n).
  3. Return G(x)=∑t=1Tαtgt(x)G(\mathbf{x}) = \sum_{t=1}^{T}\alpha_t g_t(\mathbf{x}).

Several details come from what Lin says in the lecture. The Decision Tree in the name comes from the first step: decision trees can do regression, so they are the most common choice of base algorithm. The returned GG takes no sign, because this is regression. The initial scores are 0, so the residuals in round 1 are just yny_n themselves and the problem solved is the original regression problem; learning on residuals begins from round 2.

The handout calls GBDT the regression sibling of AdaBoost-DTree, popular in practice. Lin adds in the lecture that a different derivation produces versions for problems such as logistic regression, and that this lecture demonstrates only regression. The application example given is information retrieval, such as web page ranking.

Here is what the two algorithms do in each round, side by side (this table is put together by this article; the content of every row comes from the derivations above):

AdaBoostGradientBoost (squared error)
Error functionexp⁡(−ys)\exp(-ys)(s−y)2(s - y)^2
Handed to the base algorithmthe original yny_n, plus new weights un(t)u_n^{(t)}new target values yn−sny_n - s_n
What the base algorithm solvesweighted binary classificationsquared-error regression
Step size αt\alpha_tln⁡(1−ϵt)/ϵt\ln\sqrt{(1-\epsilon_t)/\epsilon_t}∑ngt(xn)(yn−sn) / ∑ngt2(xn)\sum_n g_t(\mathbf{x}_n)(y_n - s_n)\,/\,\sum_n g_t^2(\mathbf{x}_n)
Returnsign(∑tαtgt(x))\text{sign}\big(\sum_t\alpha_t g_t(\mathbf{x})\big)∑tαtgt(x)\sum_t\alpha_t g_t(\mathbf{x})

Numerical example: three rounds of GBDT on four points

The following is an example made up for this article, not from the slides. Four one-dimensional examples:

nn1234
xnx_n1234
yny_n1326

The base algorithm is a C&RT regression tree of height 1: cut midway between two adjacent points, return on each side the average of the residuals on that side, and choose the cut with the smallest total squared error over the two sides. To keep the process easy to follow, the first three rounds do no sampling and use all four examples.

Round 1. sn=0s_n = 0, so the residuals are just y=(1,3,2,6)y = (1, 3, 2, 6). The three cuts:

Cut atLeft averageRight averageTotal squared error
1.511113\frac{11}{3}263≈8.67\frac{26}{3} \approx 8.67
2.522441010
3.5226622

Choose 3.5: g1(x)=2g_1(x) = 2 (for x<3.5x < 3.5) or 66 (for x>3.5x > 3.5), which is (2,2,2,6)(2, 2, 2, 6) on the four points. The step size is

α1=2×1+2×3+2×2+6×622+22+22+62=4848=1\alpha_1 = \frac{2\times 1 + 2\times 3 + 2\times 2 + 6\times 6}{2^2 + 2^2 + 2^2 + 6^2} = \frac{48}{48} = 1

Update s=(2,2,2,6)s = (2, 2, 2, 6); the new residuals are (−1,1,0,0)(-1, 1, 0, 0).

Round 2. Do it again on the residuals (−1,1,0,0)(-1, 1, 0, 0). Cutting at 1.5 gives left average −1-1, right average 13\frac{1}{3}, and total squared error 23\frac{2}{3}; the other two cuts both give 2. So g2=(−1,13,13,13)g_2 = (-1, \frac{1}{3}, \frac{1}{3}, \frac{1}{3}),

α2=(−1)(−1)+13×1+0+01+3×19=4/34/3=1\alpha_2 = \frac{(-1)(-1) + \frac{1}{3}\times 1 + 0 + 0}{1 + 3\times\frac{1}{9}} = \frac{4/3}{4/3} = 1

Update s=(1,73,73,193)s = (1, \frac{7}{3}, \frac{7}{3}, \frac{19}{3}), with residuals (0,23,−13,−13)(0, \frac{2}{3}, -\frac{1}{3}, -\frac{1}{3}).

Round 3. Cutting at 2.5 is best (total squared error 29\frac{2}{9}; the other two give 23\frac{2}{3} and 1427\frac{14}{27}): g3=(13,13,−13,−13)g_3 = (\frac{1}{3}, \frac{1}{3}, -\frac{1}{3}, -\frac{1}{3}), α3=1\alpha_3 = 1. Update s=(43,83,2,6)s = (\frac{4}{3}, \frac{8}{3}, 2, 6), with residuals (−13,13,0,0)(-\frac{1}{3}, \frac{1}{3}, 0, 0).

InitialAfter round 1After round 2After round 3
sns_n(0,0,0,0)(0, 0, 0, 0)(2,2,2,6)(2, 2, 2, 6)(1,73,73,193)(1, \frac{7}{3}, \frac{7}{3}, \frac{19}{3})(43,83,2,6)(\frac{4}{3}, \frac{8}{3}, 2, 6)
Residuals yn−sny_n - s_n(1,3,2,6)(1, 3, 2, 6)(−1,1,0,0)(-1, 1, 0, 0)(0,23,−13,−13)(0, \frac{2}{3}, -\frac{1}{3}, -\frac{1}{3})(−13,13,0,0)(-\frac{1}{3}, \frac{1}{3}, 0, 0)
Mean squared error12.512.50.50.516≈0.167\frac{1}{6} \approx 0.167118≈0.056\frac{1}{18} \approx 0.056

What this result means. Each round's tree makes a single cut and is weak on its own. Added together, G(x)=g1(x)+g2(x)+g3(x)G(x) = g_1(x) + g_2(x) + g_3(x) is a step function with four pieces whose values on the four points are (43,83,2,6)(\frac{4}{3}, \frac{8}{3}, 2, 6), already close to the targets (1,3,2,6)(1, 3, 2, 6). Each round's tree sees a different target: round 1 sees the original yy, and later rounds see the part not yet achieved, so the three trees cut at three different places. The mean squared error falls from 12.5 all the way to 0.056.

All three αt\alpha_t come out as exactly 1, and there is a reason (an addition in this article). Each leaf of a regression tree returns the average of the residuals that fall in that leaf. Suppose a leaf holds mm examples with residual average cc. That leaf contributes c×(sum of residuals)=c×mcc\times(\text{sum of residuals}) = c\times mc to the numerator and m×c2m\times c^2 to the denominator, and the two are equal. This holds for every leaf, so the numerator equals the denominator. As long as the tree is trained on the same data, the leaves use averages, and the outputs of gtg_t are not all 0, αt\alpha_t must be 1.

So when is the second step useful? What the handout suggests is a "sampled and pruned" C&RT. When the tree sees only the sampled data, αt\alpha_t is recomputed on all the data and need not be 1. Change round 1 so that the tree is trained only on the sampled examples 1, 3, and 4 (yy values 1,2,61, 2, 6). Cutting at 3.5 is best, with left average 32\frac{3}{2} and right 66, so on the four points g1=(32,32,32,6)g_1 = (\frac{3}{2}, \frac{3}{2}, \frac{3}{2}, 6).

α1=32(1+3+2)+6×63×94+36=4542.75=2019≈1.053\alpha_1 = \frac{\frac{3}{2}(1 + 3 + 2) + 6\times 6}{3\times\frac{9}{4} + 36} = \frac{45}{42.75} = \frac{20}{19} \approx 1.053

With α1=2019\alpha_1 = \frac{20}{19}, the mean squared error over the four examples is 2538≈0.658\frac{25}{38} \approx 0.658; using 1 directly gives 1116=0.6875\frac{11}{16} = 0.6875. The tree did not see y=3y = 3 from example 2, so the left leaf is estimated too low, and the one-variable linear regression uses all the data to scale the whole tree's output up slightly and win a little back.

The pure Python below prints the threshold, the two leaf values, αt\alpha_t, and the mean squared error for the first three rounds, so you can compare with the table above:

from fractions import Fraction as F

x = [1, 2, 3, 4]
y = [F(1), F(3), F(2), F(6)]

def stump(xs, rs):
    """Regression tree of height 1: returns (threshold, left leaf average, right leaf average)"""
    best = None
    for i in range(len(xs) - 1):
        th = F(xs[i] + xs[i + 1], 2)
        left = [r for a, r in zip(xs, rs) if a < th]
        right = [r for a, r in zip(xs, rs) if a > th]
        ml, mr = sum(left) / len(left), sum(right) / len(right)
        sse = sum((r - ml) ** 2 for r in left) + sum((r - mr) ** 2 for r in right)
        if best is None or sse < best[0]:
            best = (sse, th, ml, mr)
    return best[1:]

s = [F(0)] * 4
for t in range(1, 4):
    res = [yn - sn for yn, sn in zip(y, s)]            # residuals
    th, ml, mr = stump(x, res)                         # step 1: regression on the residuals
    g = [ml if a < th else mr for a in x]
    alpha = sum(gn * rn for gn, rn in zip(g, res)) / sum(gn * gn for gn in g)  # step 2
    s = [sn + alpha * gn for sn, gn in zip(s, g)]      # step 3
    mse = sum((yn - sn) ** 2 for yn, sn in zip(y, s)) / 4
    print(t, th, ml, mr, alpha, mse)

The output is three lines: 1 7/2 2 6 1 1/2, 2 3/2 -1 1/3 1 1/6, 3 5/2 1/3 -1/3 1 1/18.

Fun Time: the formula for the optimal step size

Question (page 19): Which of the following is the optimal η\eta for min⁡η1N∑n=1N((yn−sn)−ηgt(xn))2\min_{\eta}\frac{1}{N}\sum_{n=1}^{N}\big((y_n - s_n) - \eta g_t(\mathbf{x}_n)\big)^2? Write A=∑n=1Ngt(xn)(yn−sn)A = \sum_{n=1}^{N} g_t(\mathbf{x}_n)(y_n - s_n) and B=∑n=1Ngt2(xn)B = \sum_{n=1}^{N} g_t^2(\mathbf{x}_n) (these two symbols are added by this article for layout):

  1. A⋅BA \cdot B
  2. A / BA\,/\,B
  3. A+BA + B
  4. A−BA - B

Answer: 2. The handout only says it was derived within Lecture 9 of ML Foundations. The closed-form solution for linear regression in Foundations Lecture 9 is w=(X⊤X)−1X⊤y\mathbf{w} = (\mathrm{X}^\top\mathrm{X})^{-1}\mathrm{X}^\top\mathbf{y}. Here there is only one variable, so X\mathrm{X} is an N×1N\times 1 column holding gt(xn)g_t(\mathbf{x}_n), and y\mathbf{y} is replaced by the residuals. Then X⊤X=B\mathrm{X}^\top\mathrm{X} = B, X⊤y=A\mathrm{X}^\top\mathbf{y} = A, and η=A/B\eta = A/B. The subsection above on the step size as one-variable linear regression differentiates directly and arrives at the same expression.

The other options can be ruled out with a simple check: if gtg_t happens to equal the residuals, the optimal η\eta is obviously 1. In that case A=BA = B, and the four options give B2B^2, 11, 2B2B, and 00, so only option 2 is right. Round 1 of the example is another check: A=48A = 48, B=48B = 48, η=1\eta = 1.

A summary of aggregation models: which ones make a model stronger and which make it steadier

YouTube:Gradient Boosted Decision Tree :: Summary of Aggregation @ Machine Learning Techniques (機器學習技法)

(Video 00:00–02:08 sums up blending, 02:08–05:00 sums up the models that learn while aggregating, 05:00–06:00 is aggregation of aggregation, 06:00–08:42 discusses the two cures, 08:42–09:21 is Fun Time, and the summary of the whole lecture follows.)

From Techniques Lecture 7 to this one, five lectures have covered a whole family of models. Pages 20 to 23 gather them into three maps and one conclusion.

Get the g first, then aggregate: blending

The definition on page 20 is aggregate after getting diverse gtg_t. Lin's analogy in the lecture is throwing the gtg_t you already have into a blender to make mixed juice. Three ways to do it:

uniformnon-uniformconditional
How to aggregatesimple voting or averaginglinear model on gtg_t-transformed inputsnonlinear model on gtg_t-transformed inputs

The handout's comment: uniform for stability; non-uniform and conditional, carefully, for complexity. Lin's explanation in the lecture is that uniform lets different gtg_t correct one another's mistakes, while the other two learn one more layer after the transform, which makes them more powerful and in turn means worrying about overfitting. Lin also mentions that the conditional approach is generally called stacking, meaning that layers of learning are stacked up; this name is not on this slide.

Learn the g while aggregating: four models

The definition on page 21 is aggregate as well as getting diverse gtg_t: no gtg_t are in hand yet, and how to aggregate is decided while learning them.

ModelHow it gets diverse gtg_tHow it aggregates
Baggingbootstrappinguniform vote, with nothing to compute
AdaBoostreweightinglinear vote, with votes decided by steepest search
Decision Treedata splittingconditional vote, with conditions decided by branching
GradientBoostresidual fittinglinear vote, with votes decided by steepest search

AdaBoost and GradientBoost differ in the second column and agree in the third, which is exactly the content of this lecture's two derivations. The handout writes at the bottom of the page boosting-like algorithms most popular. What Lin says in the lecture is slightly different: all four models matter in practice, and the most popular are the two related to boosting.

Aggregating the aggregation models

Page 22 pairs the models above with each other:

Outer layerInner treeResult
Bagging (plus randomization)'strong' DTreeRandom Forest
AdaBoost'weak' DTreeAdaBoost-DTree
GradientBoost'weak' DTreeGBDT

The handout says all three are frequently used in practice. Lin explains the strong and weak distinction in the lecture: random forest uses fully grown trees and relies on random projections to make the trees more varied; AdaBoost is designed to combine weak things into something strong, so starting with something too strong makes no sense, and GradientBoost likewise goes with weak trees. This echoes the autocracy problem from the start of this lecture.

Two cures

Page 23 returns to the two motivations given at the start of Techniques Lecture 7, each with a figure:

  • Cure underfitting. The left figure shows data of circles and crosses whose boundary is a staircase made of several horizontal and vertical segments. A single decision stump can only make one horizontal or vertical cut and cannot separate the data well; after aggregation G(x)G(\mathbf{x}) becomes 'strong'. The handout's reading is aggregation ⟹ feature transform.
  • Cure overfitting. The right figure has many gray lines and one black line in the middle. Combining many of them gives a more middle-of-the-road G(x)G(\mathbf{x}) (the handout's word is moderate). In the lecture, Lin explains that overfitting means having made too extreme a choice, and that a moderate choice prevents it. The handout's reading is aggregation ⟹ regularization. Lin says the moderate choice shows up in the figure as something like a large-margin effect, and that the same phenomenon can be seen in the boundary of a random forest.

Lin compares the two sides in the lecture to a big family that has both models that step on the accelerator for you and models that step on the brake: some succeed more at curing underfitting and some at curing overfitting, and you get better performance only by knowing each one's character and using them well in turn. The handout's conclusion is proper aggregation (a.k.a. ensemble) ⟹ better performance. Lin explains the word ensemble as a group, like a choir.

An addition in this article: the two numerical examples for AdaBoost and GBDT both belong to the left-figure kind. Three stumps that each make mistakes combine to classify all five points correctly; three regression trees that each make a single cut combine into a step function with four pieces.

Question (page 24): Which of the following aggregation model learns diverse gtg_t by reweighting and calculates linear vote by steepest search?

  1. AdaBoost
  2. Random Forest
  3. Decision Tree
  4. Linear Blending

Answer: 1. The sentence is the AdaBoost row of the table on page 21. Check the other options against the same table. Random Forest gets its gtg_t by bootstrapping (plus randomized trees) and votes uniformly, with no votes to compute. Decision Tree relies on data splitting and aggregates conditionally. Linear Blending aggregates after the gtg_t already exist; it is not responsible for learning gtg_t, and its votes come from solving a linear model. GradientBoost's votes also come from steepest search, but it gets gtg_t by residual fitting, and it is not among the options.

The summary on page 25 reduces each of the four sections to one line: sampling and pruning for 'weak' trees; AdaBoost is functional gradient descent on exponential error; gradient boosting is iterative steepest residual fitting; among aggregation models some cure underfitting and some cure overfitting. The preview of the next lecture is extract features other than hypotheses: so far everything used as a feature transform has been a hypothesis gtg_t, and next the machine will learn other kinds of feature transforms on its own.

Self-check

1. In some round of AdaBoost the sum of weights is 1, and the gtg_t handed back by the base algorithm has weighted error rate ϵt=0.1\epsilon_t = 0.1. What is the optimal step size? After taking this step, what does the sum of weights become?

Answer: ηt=ln⁡0.9/0.1=ln⁡3≈1.099\eta_t = \ln\sqrt{0.9/0.1} = \ln 3 \approx 1.099. E^ADA=0.9exp⁡(−ln⁡3)+0.1exp⁡(ln⁡3)=0.3+0.3=0.6\widehat{E}_{\text{ADA}} = 0.9\exp(-\ln 3) + 0.1\exp(\ln 3) = 0.3 + 0.3 = 0.6, or directly 20.1×0.9=0.62\sqrt{0.1\times 0.9} = 0.6. The more accurate gtg_t is, the larger the step and the more the sum of weights drops.

2. In some round of GBDT the residuals of three examples are (3,−1,2)(3, -1, 2), and the learned gtg_t outputs (1,−1,1)(1, -1, 1) on these three. Compute αt\alpha_t and the updated residuals, and check the inner product of the new residuals with the outputs of gtg_t.

Answer: αt=3+1+21+1+1=2\alpha_t = \frac{3 + 1 + 2}{1 + 1 + 1} = 2. The new residuals are (3,−1,2)−2×(1,−1,1)=(1,1,0)(3, -1, 2) - 2\times(1, -1, 1) = (1, 1, 0), and the mean squared error falls from 143\frac{14}{3} to 23\frac{2}{3}. The inner product is 1×1+1×(−1)+0×1=01\times 1 + 1\times(-1) + 0\times 1 = 0. This is no coincidence: the optimal η\eta satisfies ∑ngt(xn)((yn−sn)−ηgt(xn))=0\sum_n g_t(\mathbf{x}_n)\big((y_n - s_n) - \eta g_t(\mathbf{x}_n)\big) = 0, and the bracket is exactly the updated residual.

3. Why can AdaBoost not be paired directly with a decision tree that is "trained on all the data and fully grown"? Which two remedies does the handout give?

Criterion: the answer has to walk through this chain: when all xn\mathbf{x}_n are different Ein=0E_{\text{in}} = 0, it is still 0 after weighting, ϵt=0\epsilon_t = 0, αt=∞\alpha_t = \infty, and one tree takes all the votes. The remedies are pruning (or limiting the height) and using only part of the data (sampling by u(t)\mathbf{u}^{(t)}).

4. In deriving GradientBoost's direction, why is there no meaningful hh without the penalty term? Who ends up deciding the magnitude of hh?

Criterion: the answer has to say that the objective after the Taylor expansion is first-order in h(xn)h(\mathbf{x}_n), namely ηN∑nh(xn)⋅2(sn−yn)\frac{\eta}{N}\sum_n h(\mathbf{x}_n)\cdot 2(s_n - y_n); as long as the sign is chosen opposite to sn−yns_n - y_n, the larger the magnitude the smaller the value, and there is no minimum. Adding h2h^2 lets it be completed to (h(xn)−(yn−sn))2\big(h(\mathbf{x}_n) - (y_n - s_n)\big)^2, and a minimum exists. The magnitude need not be settled in this step, because the η\eta of the next step decides the step size by one-variable linear regression.

5. In round 1 of GBDT, what problem does the base algorithm solve? If the base algorithm is a regression tree with no sampling and averages at the leaves, what is α1\alpha_1?

Answer: sns_n starts at 0, so the residuals equal yny_n and round 1 solves the original regression problem. By the argument in the numerical example, every leaf contributes equally to the numerator and the denominator, so α1=1\alpha_1 = 1.

Exercises and corresponding reading

The corresponding week in two semesters. The Fall 2024 course page puts decision tree, random forest, and this lecture in the same week (W12, 11/18), and the slide code for this lecture is 211u. The Fall 2026 course page also puts them in W12 (11/25); the slides for that week were not yet online as of 2026-09-30, so this article uses only the MOOC handout.

Textbook. Neither course page maps this lecture to a chapter of Learning from Data. Among the further readings the course pages list for this week, the one related to this lecture is Friedman, Greedy Function Approximation: A Gradient Boosting Machine (Annals of Statistics, 2001), the original gradient boosting paper; the link here uses the DOI.

Homework. Fall 2024 HW7 (released 2024-12-02, due 12-16) has three problems that correspond directly to this lecture. All are human-graded proof problems with no official solutions:

  • Q6: prove Ut+1/Ut=2ϵt(1−ϵt)U_{t+1}/U_t = 2\sqrt{\epsilon_t(1-\epsilon_t)}, where UtU_t is the sum of weights in round tt. The problem states that it corresponds to the AdaBoost of Techniques Lecture 8 and this lecture. The addition at the end of the step-size subsection is this formula, and the five-point example can be used to check the numbers.
  • Q7: when the base model of gradient boosting is replaced by linear regression without regularization, prove or disprove that the optimal α1=1\alpha_1 = 1. First get clear on why the regression tree in the numerical example gives 1, then see whether that argument still holds for linear regression.
  • Q8: after GBDT updates sns_n using the steepest η\eta as αt\alpha_t, prove ∑n(yn−sn)gt(xn)=0\sum_n (y_n - s_n) g_t(\mathbf{x}_n) = 0, and think about the relation between the residual vector and the output vector of gtg_t. Self-check question 2 is its numerical version.

This lecture has no programming problem. If you want to get your hands dirty, there are two directions. One is to turn the AdaBoost-Stump of HW7 Q10–12 into AdaBoost-DTree, sampling by the weights and limiting the tree height as this lecture describes. The other is to replace the base model in the GBDT code above with a regression tree of depth 2 and, on data from a one-dimensional sin curve with noise, plot GG at rounds 1, 5, and 20 to see how each round fills in the residuals the previous round left behind. The guide to the whole assignment is in Techniques Homework and Final Project.

Next lecture. Techniques Lecture 12: Neural Networks enters the third technique, Distilling Implicit Features: Extraction Models, where the feature transform is no longer a set of hypotheses learned one by one but is learned together with the final model.

Course video sources

Original videos: Adaptive Boosted Decision Tree, Optimization View of AdaBoost, Gradient Boosting, Summary of Aggregation Models

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. The section names in the video titles are shorter than those in the handout (AdaBoost Decision Tree, Optimization of AdaBoost, Summary of Aggregation); the links above use the section names from page 1 of the handout.

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