Machine learning · 20 min

Decision trees and boosting: twenty questions, then many small fixes

Grow a tree by Gini splits, watch it overfit, then add up small trees fitted to the residuals.

01Why it matters

Twenty questions, then many small fixes

A doctor's checklist, a bank's loan rules, the game of twenty questions: each asks one simple question, then picks the next question based on the answer. A decision tree learns such a checklist from data, and anyone can read the result.

One tree is easy to understand but easy to fool. Add up hundreds of tiny trees, each fixing the mistakes of the ones before, and you get gradient boosting, the method that wins most competitions on tabular data.

02Key parts

The pieces you will see

split
A yes/no question about one feature, like x<0.4x \lt 0.4. It cuts a region of the plane into two boxes.
Gini impurity
1−∑cpc21 - \sum_c p_c^2 for the class shares pcp_c in a region: 0 when it is pure, ½ for an even two-class mix.
leaf
A region that isn't split any further. It predicts its majority class.
residual
In boosting, what the model still gets wrong: y−F(x)y - F(x).
stump
A tree with a single split: a step, with one value on each side.

03See it work

Grow a tree on XOR

Each region tries every question on x and on y and keeps the one whose halves are purest. The tree is drawn beside the plane.

The tree is grown greedily. For a region it tries every threshold on each axis, scores each split by the Gini impurity of the two halves (weighted by their sizes), and keeps the lowest. A single question can't separate XOR, since every cut leaves both classes on both sides, but two levels of questions can: this tree gets 95% of the points right at depth 2.

Deeper isn't always better, though:

A round boundary built from boxes. At depth 5 the tree is perfect on its training points, with leaves that hold only one or two of them.

04See it work

Boosting: fit what is left

Each round fits a stump to the residuals (the bars) and adds a shrunk copy of it to the model F.

Boosting starts from a flat guess, the mean of yy. Each round it looks at the residuals, fits one stump to them, and adds η\eta times that stump to the model:

F←F+η⋅stumpF \leftarrow F + \eta \cdot \text{stump}

Each stump is weak, just one step, but together they build a staircase that follows the curve. Because each one is fitted to the current errors, the training error can only fall.

05Predict

Your turn: which question comes next?

Make 5 predictions: step forward and answer each question before the next step plays.

0 of 5 made

06Try it

Change the depth and the learning rate

Use the slider to change the maximum depth, and the buttons to change the data:

  • Moons or circles at depth 1, 3 and 5: training accuracy climbs, but the boundary turns into a staircase of tiny boxes.
  • Overlapping classes: deeper trees chase individual points into their own leaves.

For boosting, compare Small learning rate (η = 0.2) with Learning rate 1: the small rate falls more slowly but each stump changes the model gently; the full rate fixes big errors fast, then starts chasing noisy points.

07Check yourself

Check yourself

  1. Question 1 of 5

    A region holds 3 points of class A and 1 of class B. What is its Gini impurity?

    Your answer comes back in Review in a few days, so it sticks.

  2. Question 2 of 5

    Why can’t a depth-1 tree solve XOR?

  3. Question 3 of 5

    In gradient boosting, what does each new stump fit?

  4. Question 4 of 5

    Why multiply each stump by a learning rate η below 1?

  5. Question 5 of 5

    A depth-12 tree is 100% right on its training points. What does that tell you about new points?

08Explain it back

Say it in your own words

How does a decision tree choose its splits, and how does gradient boosting turn many weak trees into a strong model?

09Recap

What to remember

  • A decision tree asks one question about one feature at a time; each split is the one with the lowest weighted Gini.
  • Deep trees fit their training data perfectly and overfit; limit depth and judge on new data.
  • Gradient boosting adds shrunk stumps fitted to the residuals, so the training error only falls.
  • Small learning rates with more rounds are the usual recipe.
Back to path