One tree overfits. Two hundred vote it down.

Lesson 5 of 7About 10 minutes5 steps

A decision tree asks one yes-or-no question at a time: easy to read and easy to overfit. Forests and boosting combine many trees and run most models on business tables. Here they are on the churn table.

  • Explain how a tree chooses a split
  • Tell bagging from boosting
  • Read feature importances with care

You need: Lesson 3.

  1. 1Distributions and sampling
  2. 2Confidence intervals and tests
  3. 3Training, testing and overfitting
  4. 4Judging a classifier
  5. 5Trees and ensembles
  6. 6Clustering and PCA
  7. 7How a neural network learns
0 of 5 steps
  1. One question at a time

    Predict first

    A tree allowed one question about churn. Which column does it ask about?

    Just show me

    Tenure: “36 months or less?” On that side, 10.5% left; on the other, 3.3%.

    A tree tries every column and every cut point, and keeps the split that makes the two groups purest, by Gini impurity or entropy. Then it repeats inside each group. The result reads like a flowchart, which is why trees are easy to explain to a manager.

    36 months or less (2,530)10.5%
    More than 36 months (2,470)3.3%

    Share who left on each side of the tree’s first question (all 5,000 customers)

    Quick check

    What does a split try to make?

    Purity: each side as close to all-left or all-stayed as it can get.

  2. Deep trees memorise

    Predict first

    With no depth limit, how many leaves does a tree grow on 4,000 customers?

    Just show me

    641 leaves, scoring 1.00 on its training customers and 0.52 on new ones.

    A deep tree can carve out a leaf for a handful of customers, so it memorises noise, and a slightly different sample gives a very different tree: a single tree has high variance. Limiting the depth helps (depth 3 scored 0.72 on new customers), and so does averaging many trees.

    Quick check

    Why is a single deep tree unstable?

    High variance: the tree follows its particular sample too closely.

  3. A forest of trees

    Predict first

    200 trees, each grown on a random resample of the customers, with random columns at each split, then averaged. Against the unlimited tree’s 0.52 on new customers?

    Just show me

    0.69: averaging 200 different trees cancels much of their noise.

    That’s bagging (bootstrap aggregating) plus random columns: a random forest. Each tree overfits in its own way, and the average smooths the quirks out. An honest note from this table: the pruned depth-3 tree (0.72) and plain logistic regression (0.68) did about as well, because the pattern is simple. Always compare with a simple model before reaching for a complex one.

    One tree, no limit0.52
    Logistic regression0.68
    Random forest, 200 trees0.69
    One tree, depth 30.72

    AUC on the 1,000 test customers (0.5 is a coin toss), scikit-learn 1.8.0

    Quick check

    What makes a forest’s trees differ from each other?

    Randomness in rows and columns makes the trees disagree, so their average is steadier.

  4. Boosting: trees that fix mistakes

    Predict first

    Bagging grows its trees independently. How does boosting grow them?

    Just show me

    One after another: each new small tree fits what the model so far still gets wrong.

    Gradient boosting (XGBoost, LightGBM, CatBoost) adds shallow trees in sequence, each moving the predictions a small step, set by the learning rate. It usually wins on business tables but needs care: too many trees or too big a learning rate overfits, so the number of trees is chosen by early stopping on validation data.

    Quick check

    Bagging mainly reduces…

    Averaging many high-variance trees reduces variance; boosting mainly reduces bias.

  5. What mattered, and a trap

    Predict first

    Which column does the forest lean on most?

    Just show me

    Tenure: 47% of the forest’s importance; the monthly charge 28%, complaints 18%.

    Now the trap: the monthly charge has no effect on churn at all, because the table’s code makes churn depend only on tenure and complaints. It scores high because this kind of importance favours columns with many different values, which give the trees many chances to split on noise. Permutation importance, measured on test data, is the safer check.

    Tenure46.8%
    Monthly charge27.7%
    Complaints in 90 days17.9%
    City tier 21.7%

    The forest’s built-in importances (scikit-learn’s feature_importances_, based on impurity); the highlighted one has no real effect

    Quick check

    A column of unique customer IDs gets a high built-in importance. Why?

    Impurity-based importance leans toward columns with many values; check with permutation importance on held-out data.

In the interview: trees and ensembles.

Ask Prism about this lesson

Sources

  1. Breiman, “Random Forests”, Machine Learning, 2001.
  2. Strobl, Boulesteix, Zeileis and Hothorn, “Bias in random forest variable importance measures”, BMC Bioinformatics, 2007.
  3. scikit-learn, “Ensembles: Gradient boosting, random forests, bagging, voting, stacking”.
  4. The ML guide’s churn table, the trees and forest here fitted with scikit-learn 1.8.0.

Back: lesson 4, Judging a classifier