Tree Models in Practice

Decision trees and random forests as applied methods. A tree as a sequence of threshold questions that cuts the inputs into rectangles; regression trees with the residual-sum-of-squares criterion and cost-complexity pruning chosen by cross-validation; classification trees with the Gini index and entropy; and random forests, where averaging decorrelated trees removes most of a tree's variance. Worked on breast cancer biopsies, the diabetes study, the Challenger flights, three wine cultivars and Friedman's synthetic regression problem.

A decision tree predicts by asking a short sequence of yes-or-no questions about the inputs, such as "is the worst radius of the cell nuclei at most 16.8?", and answering with the average or the majority class of the training cases that gave the same answers. Trees are easy to read, handle numbers and categories alike, and need no scaling of the inputs. They are also unstable, and the strongest methods for tabular data average many of them. This unit covers how a single tree is grown, judged and pruned, and how a random forest turns many unstable trees into a stable predictor.

The unit is the applied introduction. It sits after the Supervised Learning section of the collection, whose overview defines the regression function and the Bayes classifier that every tree approximates, and it uses the tools of the Evaluating Model Performance section throughout: cross-validation to choose a tree's size, the bias-variance tradeoff to explain why depth matters, and the bootstrap behind bagging and out-of-bag error.

Order. The introduction comes first, because it sets out the structure, the greedy growing procedure and the two weaknesses the other articles address. Regression trees follow, since squared error gives the cleanest derivation of a split and of pruning. Classification trees then replace the residual sum of squares by impurity measures and show that the Gini index is a residual sum of squares in disguise. Random forests close the unit by attacking the instability.

Running data. The Wisconsin breast cancer data (569 tumors, 30 measurements of cell nuclei) run through all four articles: the first tree, the instability across bootstrap samples, pruning a classification tree, and the forest with its importance measures. The diabetes study (442 patients, ten baseline measurements, disease progression after a year) serves the regression tree and its pruning and the regression forests. The 23 Challenger flights are small enough to split by hand, the wine data (178 wines, three cultivars) show a three-class tree, and Friedman's synthetic problem, where fresh training sets can be drawn at will, lets the forest article measure correlation and variance directly.

What is proved, shown and cited. Proved on the pages: the invariance of a tree to increasing transformations of its inputs, the price of a staircase boundary, the leaf mean and the split criterion for squared error, the best pruned subtree for any penalty, the Gini index as a residual sum of squares and entropy as a log-likelihood, the ordering shortcut for categorical splits with two classes, the variance of an average of correlated trees and its floor, and the out-of-bag fraction. Cited: the NP-completeness of a related optimal-tree problem (Hyafil and Rivest, 1976), the weakest-link theorem of Breiman, Friedman, Olshen and Stone (1984), the shortcut for entropy, and Breiman's (2001) convergence theorem and error bounds for forests. Shown by the scripts in tools/experiments/data-science/: every number, including an exhaustive search that finds a depth-2 tree with 22 errors where the greedy one makes 33.

Articles

  • Introduction to Decision Trees: the parts of a tree; a tree as a partition into rectangles; recursive binary splitting and why it is greedy; depth as the control of overfitting, with cross-validated accuracy peaking at 0.942; boundaries made of steps; and instability, with depth-2 trees on 200 bootstrap samples choosing five different roots. Worked problems find the best depth-2 tree by exhaustive search and price a staircase at $1/(4k)$.
  • Regression Trees: the leaf mean and the split criterion derived, a split shown to compare two means, splitting by hand on eight patients, and cost-complexity pruning derived and chosen by cross-validation: four leaves for the diabetes data, with a nested cross-validated $R^2$ of 0.332 against 0.484 for linear regression. Worked problems prove that weakest-link pruning finds the best subtree and why the checkerboard's first split is worthless.
  • Classification Trees: the misclassification rate, Gini index and entropy, with three readings of the Gini index and entropy as a log-likelihood; splits by hand on the Challenger flights; why a concave impurity is needed; a three-class tree for the wines; pruning to an honest 0.933; and categorical inputs. Worked problems prove the ordering shortcut, locate where Gini and entropy disagree, and measure how overconfident a fully grown tree's probabilities are.
  • Random Forests: the variance of an average of correlated trees and its floor $\rho\sigma^2$; random input selection at each split; correlation, variance and bias measured on Friedman's problem; why more trees do not overfit; out-of-bag error; variable importance by impurity and by permutation; and forests against single trees and linear regression. Worked problems derive the out-of-bag counts and the number of trees a forest needs, and permute correlated inputs together.

Where the site goes deeper

The Ensemble Techniques section of this collection continues the story: Bagging treats bootstrap aggregation for any unstable method, and Boosting grows trees in sequence, each fitted to the errors of those before. The Statistics collection holds the theory beneath these pages. Prediction Error and Model Choice proves what cross-validation estimates and how much a training error flatters a flexible fit, which is how a tree's size is chosen here. Statistical Learning Theory proves when a training error can be trusted at all, from Empirical Risk Minimization to The VC Dimension. Information Theory is the home of entropy, and its article Mutual Information identifies the information gain of a split with a mutual information. In the Academics section, the Text Classification topic uses the same information gain to choose terms in Feature Selection, and the Learning to Rank collection builds its rankers from boosted regression trees in LambdaRank and LambdaMART, measuring the same two kinds of importance in Features for Ranking.

Several subjects these pages touch would support fuller treatment in a later collection on machine learning: trees fitted by exact optimization rather than greedy search, second-order gradient boosting and the systems built on it, the bias of impurity-based importance, and the comparison of tree ensembles with neural networks on tabular data.

References

Each article lists its own references. The sources the unit draws on throughout: record · 4 pages

  • Breiman, L. (2001). Random forests. Machine Learning, 45(1), 5–32. record · 3 pages
  • Breiman, L., Friedman, J. H., Olshen, R. A., and Stone, C. J. (1984). Classification and Regression Trees. Wadsworth. record · 4 pages
  • Hastie, T., Tibshirani, R., and Friedman, J. (2009). The Elements of Statistical Learning: Data Mining, Inference, and Prediction (2nd ed.). Springer. Section 9.2 and chapter 15. record · 39 pages
  • James, G., Witten, D., Hastie, T., and Tibshirani, R. (2021). An Introduction to Statistical Learning with Applications in R (2nd ed.). Springer. Chapter 8. record · 39 pages