S1444 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

S14 · Lesson 44 · Decision trees and ensembles

Growing a decision tree by impurity reduction with Gini and entropy, why deep trees overfit, bagging and the variance of an average of correlated models, bootstrap samples, random forests, and boosting with AdaBoost's weights

A decision tree asks a sequence of yes-or-no questions about the input, "is the supply current above 40 mA?", "is the temperature below 60 °C?", and reads a prediction off the leaf it lands in. Trees handle mixed data with no scaling, are easy to explain to a test engineer, and on their own overfit badly. Combining hundreds of them fixes that: averaging trees trained on resampled data cuts their variance, and training them in sequence on each other's mistakes cuts their bias. On tabular data, random forests and gradient-boosted trees are still often the strongest methods available.

  • An ensemble averages B models, each with prediction variance σ² = 1, whose errors have pairwise correlation ρ. Its variance is ρσ2+(1−ρ)σ2/B.
  • Adding models helps quickly at first, then the curve flattens at ρσ²: correlated errors don't average away.
  • Random forests lower ρ by giving each tree a random subset of features at every split.

Predict

A node holds 40 positive and 60 negative examples. A split sends 30 positive and 10 negative left, the rest right. By how much does it reduce the Gini impurity?

Name it

Growing a tree

At each node, choose the feature and threshold whose split most reduces an impurity measure, averaged over the children by their sizes. For a node whose class fractions are pk:

  • Gini impurity 1−∑kpk2, which is 2p(1−p) for two classes;
  • entropy −∑kpklog2⁡pk, whose reduction is the information gain.

Splitting continues until the leaves are pure or too small. A fully grown tree fits its training data perfectly and has high variance, so trees are limited in depth or pruned back using validation data.

Bagging

Bootstrap aggregating trains each of B models on a bootstrap sample (N draws with replacement from the N examples) and averages them. Each bootstrap sample contains a fraction 1−(1−1/N)N≈1−1/e = 63.2% of the distinct examples; the left-out ones give a free validation set. Averaging B models of variance σ² with correlation ρ gives

variance=ρσ2+1−ρBσ2

Random forests decorrelate the trees further by considering only a random subset of features at each split.

Boosting

AdaBoost trains weak learners in sequence on reweighted data. A learner with weighted error ε gets the vote

α=12ln⁡1−εε

and the weights of the examples it got wrong are multiplied by eα, those it got right by e−α, then renormalized; afterward the misclassified examples carry exactly half the total weight. Gradient boosting generalizes this by fitting each new tree to the residual errors of the ensemble so far.

Worked example

Find the information gain of the predict question's split.

Show the solution
  1. Parent entropy. H(0.4)=0.971bits
  2. Children. They have H(0.75) = 0.811 and H(1/6) = 0.650 bits, weighted 0.4H(0.75)+0.6H(1/6)=0.715bits
  3. Gain. 0.971−0.715=0.256bits
  4. Gini. Gini and entropy usually pick the same splits.

Answer the split's information gain is 0.256 bits.

Worked example

A weak learner has weighted error 0.3. What's its vote, how do the weights change, and what does averaging 50 trees with ρ = 0.3 achieve?

Show the solution
  1. Vote. α=12ln⁡(0.7/0.3)=0.424
  2. Reweight. Misclassified weights grow by e0.424 = 1.528 and correct ones shrink by 0.655, so the misclassified 30% become 0.3×1.5280.3×1.528+0.7×0.655=50% of the weight.
  3. Averaging trees. Fifty trees with ρ = 0.3 have variance (0.3+0.7/50)σ2=0.314σ2 most of the way to the floor of 0.3σ².

Answer the learner's vote is 0.424, the misclassified examples grow to half the weight, and averaging 50 trees gives a variance of 0.314σ².

Worked example

Boost a regression stump on the targets 3, 5 and 10 with squared loss and a learning rate of 0.5, starting from their mean.

Show the solution
  1. Start from the mean. The mean is 6, so the residuals are −3, −1 and 4, with a mean squared error of 8.67.
  2. Fit a stump. The best stump splits {3, 5} from {10}, predicting their mean residuals, −2 and 4.
  3. Update. Adding half of that gives predictions 5, 5 and 8, residuals −2, 0 and 2, and a mean squared error of 2.67.
  4. What boosting does. Each round fits the current residuals, the negative gradient of squared loss, and the learning rate keeps any one tree from taking over; gradient boosting is gradient descent in the space of functions.

Answer after one round the predictions are 5, 5 and 8, and the mean squared error falls from 8.67 to 2.67.

Check

A node's examples are 0.3 positive. What's its Gini impurity?

Check

A split sends 20 positive and 5 negative examples left and 15 positive and 60 negative right. By how much does it reduce the Gini impurity?

Check

100 models, each with prediction variance 1, have pairwise error correlation 0.4. What's the variance of their average?

Check

A bootstrap sample draws 5 times with replacement from 5 examples. What fraction of the examples does it contain on average?

Check

An AdaBoost weak learner has weighted error 0.25. What's its vote α?

Check

By what factor does AdaBoost multiply the weight of an example that a learner with error 0.25 misclassified (before renormalizing)?

Check

A regression stump splits the targets 1 and 3 from 12; gradient boosting starts from their mean with learning rate 1.

(a)

By how much does the split reduce the mean squared error about the mean?

(b)

What mean squared error remains after one boosting step?

Check

B models each have prediction variance s, with pairwise error correlation ρ.

Step 1

What is the variance of their average?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Explain why

Why does averaging many trees help, and why does it stop helping?

Practice

Keep practicing

10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.