Tree-Based Methods

Tree-based methods predict from tabular data by splitting the feature space into boxes and giving each box a constant prediction. Every method in the family takes a feature vector with numeric or categorical entries. It returns a number for regression, or a class and its probability for classification. All of them build on the CART trees of Breiman et al. (1984). They differ in how many trees they grow and how they combine them:

  • Decision tree: one tree, grown greedily and then pruned.
  • Random forest: the average of many deep trees, each grown on a bootstrap sample with random feature subsets.
  • Gradient boosted trees: the sum of many shallow trees, each fit to the errors of the trees before it.

The decision rule is as follows:

  • Gradient boosted trees are the default when accuracy on tabular data matters most and there is time to tune.
  • A random forest is the strong baseline that works with little tuning.
  • A single shallow tree fits when people must read, audit or apply the model by hand.

Intuition

The depth of a single tree controls its bias and variance. A deep tree follows the training data closely and changes a lot when the data change. A shallow tree is stable but too coarse for complex patterns. The two ensembles reduce different terms of the bias-variance decomposition. A random forest starts from deep trees with low bias and high variance. Averaging them lowers the variance and leaves the bias where it was. Gradient boosting starts from shallow trees with high bias and low variance. Adding them in sequence, each fit to the remaining errors, lowers the bias step by step.

The three methods also differ in readability and tuning effort. One shallow tree fits on a page, and a doctor can check every rule in it. Nobody can read a forest of deep trees, but the forest works well with default settings. Boosting usually gives the lowest test error. It also has the most hyperparameters. The learning rate, the number of trees and the depth interact with each other.

The animation fits three models to the same 60 points. One tree builds its boundary from horizontal and vertical pieces. The forest and the boosted model both reach higher test accuracy.

\usepackage{tikz}
\usetikzlibrary{animations, arrows.meta}
\begin{document}
\definecolor{hot}{HTML}{D9483B}
\definecolor{cold}{HTML}{2F80ED}
\definecolor{mid}{HTML}{8A8A8A}
\newcommand{\pa}[1]{\filldraw[draw=black, fill=cold] (#1) circle (2.2pt);}
\newcommand{\pb}[1]{\filldraw[draw=black, fill=white] (#1) ++(-1.9pt,-1.9pt) rectangle ++(3.8pt,3.8pt);}
\begin{tikzpicture}[font=\small, >={Stealth[length=2.2mm]}]
\draw (0,0) rectangle (4.5,4.5);
\draw[mid, dashed, thick] (0.00,1.57) -- (0.15,1.79) -- (0.30,2.01) -- (0.45,2.25) -- (0.60,2.49) -- (0.75,2.71) -- (0.90,2.93) -- (1.05,3.11) -- (1.20,3.27) -- (1.35,3.39) -- (1.50,3.47) -- (1.65,3.51) -- (1.80,3.50) -- (1.95,3.45) -- (2.10,3.35) -- (2.25,3.22) -- (2.40,3.05) -- (2.55,2.86) -- (2.70,2.64) -- (2.85,2.41) -- (3.00,2.17) -- (3.15,1.94) -- (3.30,1.71) -- (3.45,1.51) -- (3.60,1.33) -- (3.75,1.19) -- (3.90,1.08) -- (4.05,1.01) -- (4.20,0.99) -- (4.35,1.01) -- (4.50,1.08);
\node at (2.25,4.85) {one tree, depth $4$};
\pa{1.89,4.17}\pb{1.23,0.27}\pb{1.40,3.23}\pa{3.51,2.42}\pa{1.40,4.12}\pa{4.18,1.96}\pb{1.84,2.76}\pa{3.21,2.79}\pb{1.95,1.99}\pa{2.91,4.13}\pb{0.22,0.40}\pa{3.43,2.07}\pa{3.50,2.43}\pa{2.08,4.29}\pb{1.66,2.91}\pb{2.45,0.50}\pa{0.75,3.68}\pb{2.35,3.06}\pa{2.04,3.82}\pa{3.83,1.94}\pa{0.58,3.74}\pb{2.25,2.50}\pb{2.29,0.17}\pb{2.31,0.43}\pa{0.28,3.72}\pa{0.64,3.25}\pb{1.98,2.26}\pb{2.29,0.75}\pa{0.29,2.87}\pb{0.46,0.29}\pa{0.20,2.72}\pa{4.26,2.43}\pa{0.07,2.61}\pb{2.15,3.09}\pa{0.53,3.03}\pb{4.19,0.98}\pa{4.28,2.72}\pb{3.80,0.94}\pa{1.74,3.93}\pa{3.74,2.65}\pa{3.32,2.56}\pb{2.01,1.38}\pb{2.24,2.33}\pb{2.17,0.05}\pa{4.41,4.46}\pb{3.20,0.83}\pa{3.94,1.13}\pb{0.17,0.83}\pa{3.55,3.92}\pa{4.33,3.62}\pb{1.38,2.49}\pb{3.15,0.25}\pa{0.38,3.21}\pb{1.54,0.42}\pb{2.26,0.41}\pb{3.02,0.38}\pa{4.39,3.70}\pb{0.92,0.69}\pb{3.20,1.06}\pa{3.90,3.39}
\draw (5.25,0) rectangle (9.75,4.5);
\draw[mid, dashed, thick] (5.25,1.57) -- (5.40,1.79) -- (5.55,2.01) -- (5.70,2.25) -- (5.85,2.49) -- (6.00,2.71) -- (6.15,2.93) -- (6.30,3.11) -- (6.45,3.27) -- (6.60,3.39) -- (6.75,3.47) -- (6.90,3.51) -- (7.05,3.50) -- (7.20,3.45) -- (7.35,3.35) -- (7.50,3.22) -- (7.65,3.05) -- (7.80,2.86) -- (7.95,2.64) -- (8.10,2.41) -- (8.25,2.17) -- (8.40,1.94) -- (8.55,1.71) -- (8.70,1.51) -- (8.85,1.33) -- (9.00,1.19) -- (9.15,1.08) -- (9.30,1.01) -- (9.45,0.99) -- (9.60,1.01) -- (9.75,1.08);
\node at (7.50,4.85) {random forest, $B = 100$};
\pa{7.14,4.17}\pb{6.48,0.27}\pb{6.65,3.23}\pa{8.76,2.42}\pa{6.65,4.12}\pa{9.43,1.96}\pb{7.09,2.76}\pa{8.46,2.79}\pb{7.20,1.99}\pa{8.16,4.13}\pb{5.47,0.40}\pa{8.68,2.07}\pa{8.75,2.43}\pa{7.33,4.29}\pb{6.91,2.91}\pb{7.70,0.50}\pa{6.00,3.68}\pb{7.60,3.06}\pa{7.29,3.82}\pa{9.08,1.94}\pa{5.83,3.74}\pb{7.50,2.50}\pb{7.54,0.17}\pb{7.56,0.43}\pa{5.53,3.72}\pa{5.89,3.25}\pb{7.23,2.26}\pb{7.54,0.75}\pa{5.54,2.87}\pb{5.71,0.29}\pa{5.45,2.72}\pa{9.51,2.43}\pa{5.32,2.61}\pb{7.40,3.09}\pa{5.78,3.03}\pb{9.44,0.98}\pa{9.53,2.72}\pb{9.05,0.94}\pa{6.99,3.93}\pa{8.99,2.65}\pa{8.57,2.56}\pb{7.26,1.38}\pb{7.49,2.33}\pb{7.42,0.05}\pa{9.66,4.46}\pb{8.45,0.83}\pa{9.19,1.13}\pb{5.42,0.83}\pa{8.80,3.92}\pa{9.58,3.62}\pb{6.63,2.49}\pb{8.40,0.25}\pa{5.63,3.21}\pb{6.79,0.42}\pb{7.51,0.41}\pb{8.27,0.38}\pa{9.64,3.70}\pb{6.17,0.69}\pb{8.45,1.06}\pa{9.15,3.39}
\draw (10.5,0) rectangle (15.0,4.5);
\draw[mid, dashed, thick] (10.50,1.57) -- (10.65,1.79) -- (10.80,2.01) -- (10.95,2.25) -- (11.10,2.49) -- (11.25,2.71) -- (11.40,2.93) -- (11.55,3.11) -- (11.70,3.27) -- (11.85,3.39) -- (12.00,3.47) -- (12.15,3.51) -- (12.30,3.50) -- (12.45,3.45) -- (12.60,3.35) -- (12.75,3.22) -- (12.90,3.05) -- (13.05,2.86) -- (13.20,2.64) -- (13.35,2.41) -- (13.50,2.17) -- (13.65,1.94) -- (13.80,1.71) -- (13.95,1.51) -- (14.10,1.33) -- (14.25,1.19) -- (14.40,1.08) -- (14.55,1.01) -- (14.70,0.99) -- (14.85,1.01) -- (15.00,1.08);
\node at (12.75,4.85) {boosting, $M = 100$};
\pa{12.39,4.17}\pb{11.73,0.27}\pb{11.90,3.23}\pa{14.01,2.42}\pa{11.90,4.12}\pa{14.68,1.96}\pb{12.34,2.76}\pa{13.71,2.79}\pb{12.45,1.99}\pa{13.41,4.13}\pb{10.72,0.40}\pa{13.93,2.07}\pa{14.00,2.43}\pa{12.58,4.29}\pb{12.16,2.91}\pb{12.95,0.50}\pa{11.25,3.68}\pb{12.85,3.06}\pa{12.54,3.82}\pa{14.33,1.94}\pa{11.08,3.74}\pb{12.75,2.50}\pb{12.79,0.17}\pb{12.81,0.43}\pa{10.78,3.72}\pa{11.14,3.25}\pb{12.48,2.26}\pb{12.79,0.75}\pa{10.79,2.87}\pb{10.96,0.29}\pa{10.70,2.72}\pa{14.76,2.43}\pa{10.57,2.61}\pb{12.65,3.09}\pa{11.03,3.03}\pb{14.69,0.98}\pa{14.78,2.72}\pb{14.30,0.94}\pa{12.24,3.93}\pa{14.24,2.65}\pa{13.82,2.56}\pb{12.51,1.38}\pb{12.74,2.33}\pb{12.67,0.05}\pa{14.91,4.46}\pb{13.70,0.83}\pa{14.44,1.13}\pb{10.67,0.83}\pa{14.05,3.92}\pa{14.83,3.62}\pb{11.88,2.49}\pb{13.65,0.25}\pa{10.88,3.21}\pb{12.04,0.42}\pb{12.76,0.41}\pb{13.52,0.38}\pa{14.89,3.70}\pb{11.42,0.69}\pb{13.70,1.06}\pa{14.40,3.39}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.2s = "true", 14s = "true", repeats}}}]
\draw[hot, very thick] (0.00,1.09) -- (1.07,1.09) -- (1.07,3.53) -- (2.63,3.53) -- (2.63,1.09) -- (4.50,1.09);
\node at (2.25,-0.45) {test accuracy $0.848$};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 5s = "true", 14s = "true", repeats}}}]
\draw[hot, very thick] (5.25,1.85) -- (5.39,1.85) -- (5.39,1.98) -- (5.25,1.98);
\draw[hot, very thick] (5.25,2.03) -- (5.37,2.03) -- (5.37,2.10) -- (5.25,2.10);
\draw[hot, very thick] (5.25,2.34) -- (5.37,2.34) -- (5.37,2.38) -- (5.50,2.38) -- (5.50,2.34) -- (5.97,2.38) -- (5.97,2.53) -- (6.13,2.56) -- (6.14,2.61) -- (6.20,2.61) -- (6.21,3.04) -- (6.14,3.06) -- (6.14,3.15) -- (6.21,3.15) -- (6.20,3.24) -- (6.33,3.24) -- (6.33,3.31) -- (6.65,3.31) -- (6.65,3.24) -- (6.78,3.24) -- (6.78,3.31) -- (7.26,3.31) -- (7.26,3.24) -- (7.35,3.24) -- (7.35,3.31) -- (7.88,3.31) -- (7.88,3.24) -- (8.08,3.24) -- (8.03,3.22) -- (8.03,3.15) -- (8.14,3.13) -- (8.14,3.06) -- (8.09,3.06) -- (8.08,2.89) -- (8.03,2.89) -- (8.04,2.56) -- (8.09,2.56) -- (8.09,2.38) -- (8.43,2.34) -- (8.43,2.17) -- (8.37,2.17) -- (8.37,2.03) -- (8.43,2.03) -- (8.43,1.98) -- (8.37,1.98) -- (8.37,1.67) -- (8.45,1.66) -- (8.46,1.09) -- (8.57,1.09) -- (8.57,1.05) -- (9.02,1.05) -- (9.02,1.09) -- (9.10,1.09) -- (9.10,1.05) -- (9.43,1.05) -- (9.43,1.09) -- (9.47,1.09) -- (9.47,1.05) -- (9.75,1.05);
\draw[hot, very thick] (5.44,1.85) -- (5.44,1.98) -- (5.55,1.98) -- (5.55,2.03) -- (5.50,2.03) -- (5.50,2.10) -- (5.67,2.10) -- (5.67,2.03) -- (5.62,2.03) -- (5.62,1.98) -- (5.67,1.98) -- (5.67,1.85) -- (5.44,1.85);
\draw[hot, very thick] (5.75,1.85) -- (5.75,1.98) -- (5.97,1.98) -- (5.97,1.85) -- (5.75,1.85);
\node at (7.50,-0.45) {test accuracy $0.921$};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 7.8s = "true", 14s = "true", repeats}}}]
\draw[hot, very thick] (10.50,1.72) -- (11.34,1.72) -- (11.34,3.24) -- (13.56,3.24) -- (13.56,2.53) -- (13.71,2.53) -- (13.71,1.09) -- (15.00,1.09);
\node at (12.75,-0.45) {test accuracy $0.907$};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "true", 2.2s = "false", 14s = "false", repeats}}}]
\node[anchor=west] at (-0.1,-1.1) {Sixty training points, two classes. The dashed curve is the true boundary.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.2s = "true", 5s = "false", 14s = "false", repeats}}}]
\node[anchor=west] at (-0.1,-1.1) {One tree with $5$ leaves: every boundary piece is horizontal or vertical.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 5s = "true", 7.8s = "false", 14s = "false", repeats}}}]
\node[anchor=west] at (-0.1,-1.1) {A forest averages $100$ deep trees. Its boundary has many small steps.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 7.8s = "true", 10.6s = "false", 14s = "false", repeats}}}]
\node[anchor=west] at (-0.1,-1.1) {Boosting adds $100$ trees of depth $2$ in sequence. Each one corrects the sum so far.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 10.6s = "true", 14s = "true", repeats}}}]
\node[anchor=west] at (-0.1,-1.1) {Both ensembles beat the single tree on $4000$ test points.};
\end{scope}
\pa{0.05,-1.7} \node[anchor=west] at (0.18,-1.7) {\footnotesize class $1$};
\pb{1.55,-1.7} \node[anchor=west] at (1.68,-1.7) {\footnotesize class $0$};
\draw[hot, very thick] (3.05,-1.7) -- (3.55,-1.7) node[right, text=black] {\footnotesize model boundary};
\draw[mid, dashed, thick] (6.0,-1.7) -- (6.5,-1.7) node[right, text=black] {\footnotesize true boundary};
\end{tikzpicture}
\end{document}

Comparison Table

MethodHow trees combineWhat combining reducesMain hyperparametersCan more trees overfitParallel trainingInterpretability
Decision treeone treenothingmax depth, min leaf size, pruning penalty does not applydoes not applyhigh when shallow, low when deep
Random forestaverage or vote of independent deep treesvariancenumber of trees , features per split , min leaf sizeno, the error levels offyes, the trees are independentlow, feature importances only
Gradient boosted treessum of shallow trees fit in sequencebiaslearning rate , number of trees , depth, subsampling, , yes, early stopping picks only within each tree’s split searchlow, feature importances only

When to Use Which

Start with gradient boosted trees (XGBoost, LightGBM or CatBoost) when the data form a table and accuracy matters. Grinsztajn, Oyallon and Varoquaux (2022) benchmarked medium-sized tabular datasets. They found tree ensembles ahead of deep networks, with boosted trees at or near the top. Tune the learning rate, the depth and the number of trees, and stop early on a validation set. Fit a random forest first when a new problem needs a quick, reliable baseline. Its defaults rarely fail badly, and its out-of-bag error estimates the test error without a separate validation set. A team can later compare the forest with a tuned boosted model to see how much the tuning gained.

Choose a single shallow tree when people must understand, audit or apply the model by hand. Its depth is usually or . A triage rule for nurses and a credit policy that a regulator must check are typical cases. Expect lower accuracy from the single tree, and compare it with a forest to measure the cost. Leave the family when the data do not suit trees. For images, text and audio, use 2. Neural Networks. For a target that must be extrapolated beyond the training range, use a model such as 3.1. Linear Regression. Trees predict constants outside the data. On small datasets with smooth relationships, a penalized linear model such as 3.2.1. Ridge Regression is often more accurate.

Examples

(Easy) Choosing a Tree Model

A hospital wants a rule that nurses can apply on paper to decide which patients see a doctor first. A lender has two million past loans and wants the highest possible AUC for predicting default. A startup has rows of sensor data and wants to know within a day how predictable machine failures are.

See Also