Simple Algorithm
Machine Learning · Convergence · 26 min

Trees as Adaptive Partitions

Consistency, bias–variance and the instability of single trees.

A tree is a histogram whose bins are chosen by the data. Seen that way, questions about trees become questions about partitioning estimators: when they converge to the best possible predictor, how fast, why a single tree's partition swings so wildly with the sample, and how to make its leaf estimates honest enough for confidence intervals.

What you’ll learn

  • Write tree predictions as local averages over data-dependent cells, and state when partitioning estimates are universally consistent.
  • Derive the bias–variance bound for a cubic partition and the resulting n−2/(d+2)n^{-2/(d+2)} rate for Lipschitz regression functions, and explain what adaptive cells can and cannot gain.
  • Explain why greedy trees are unstable, and compute how bagging smooths a hard threshold.
  • Define honest trees, and explain the selection bias they remove and the inference they make possible.

Trees as local averages

Every tree prediction is a local average. If the leaves partition the input space into cells, and A(x)A(\mathbf x) is the cell containing x\mathbf x with N(A)N(A) training points, a regression tree predicts

mn(x)=∑i=1nWni(x) yi,Wni(x)=1{xi∈A(x)}N(A(x))m_n(\mathbf x)=\sum_{i=1}^n W_{ni}(\mathbf x)\,y_i,\qquad W_{ni}(\mathbf x)=\frac{\mathbf 1\{\mathbf x_i\in A(\mathbf x)\}}{N(A(\mathbf x))}
(and mn(x)=0m_n(\mathbf x)=0 if the cell is empty). A histogram does the same with cells fixed in advance; a tree chooses its cells from the data. A classification tree is the plug-in rule gn(x)=1{ηn(x)>1/2}g_n(\mathbf x)=\mathbf 1\{\eta_n(\mathbf x)>1/2\}, where ηn\eta_n is the same local average of 0/1 labels, estimating η(x)=Pr⁡(y=1∣x)\eta(\mathbf x)=\Pr(y=1\mid\mathbf x).

Plug-in rules inherit their quality from the regression estimate. Where gng_n disagrees with the Bayes rule, η(x)\eta(\mathbf x) and ηn(x)\eta_n(\mathbf x) lie on opposite sides of 1/21/2, so the extra conditional error ∣2η(x)−1∣\abs{2\eta(\mathbf x)-1} is at most 2∣ηn(x)−η(x)∣2\abs{\eta_n(\mathbf x)-\eta(\mathbf x)}. Averaging over x\mathbf x bounds the excess over the Bayes error L∗L^* (Devroye, Györfi & Lugosi, 1996):

L(gn)−L∗ ≤ 2 E∣ηn(X)−η(X)∣ ≤ 2E(ηn(X)−η(X))2L(g_n)-L^*\ \le\ 2\,\E\abs{\eta_n(X)-\eta(X)}\ \le\ 2\sqrt{\E\big(\eta_n(X)-\eta(X)\big)^2}
So a consistent regression estimate of η\eta gives a consistent classifier.

Condition (i) kills the bias and condition (ii) the variance: cells shrink, yet hold more and more points on average. When the partition depends on the data, as a tree's does, these conditions are not enough on their own. Lugosi & Nobel (1996) gave conditions for data-dependent partitions: in addition, the family of partitions the rule can produce must not be too rich (its combinatorial complexity must grow subexponentially, a Vapnik–Chervonenkis-type requirement), and the cells must shrink and fill up in probability. Rules such as statistically equivalent blocks, which split at order statistics of the inputs, meet them. Greedy CART splits, chosen to fit the labels, are much harder to analyze, and their consistency in general is only partly understood.

Bias, variance and the rate

To see the trade-off quantitatively, take x∈[0,1]d\mathbf x\in[0,1]^d, a regular partition into K=h−dK=h^{-d} cubes of side hh, a regression function mm that is CC-Lipschitz, and noise with Var⁡(y∣x)≤σ2\Var(y\mid\mathbf x)\le\sigma^2.

DerivationThe bias–variance bound for a cubic partition
  1. E[(mn(x)−m(x))2 ∣ x1,…,xn] ≤ σ2N(A(x))+C2d h2(N≥1)\E\big[(m_n(\mathbf x)-m(\mathbf x))^2\,\big|\,\mathbf x_1,\dots,\mathbf x_n\big]\ \le\ \frac{\sigma^2}{N(A(\mathbf x))}+C^2d\,h^2\qquad(N\ge1)

    Condition on the inputs. In a cell AA with N≥1N\ge1 points, the estimate averages NN independent responses, so its variance is at most σ2/N\sigma^2/N; its mean averages mm over points of AA, each within Cdiam⁡A=Cd hC\operatorname{diam}A=C\sqrt d\,h of m(x)m(\mathbf x):

  2. E∫(mn−m)2 dμ ≤ (2σ2+∥m∥∞2e)h−dn+C2d h2\E\int(m_n-m)^2\,d\mu\ \le\ \Big(2\sigma^2+\frac{\norm m_\infty^2}{e}\Big)\frac{h^{-d}}{n}+C^2d\,h^2

    Average over the inputs. N(A)N(A) is Binomial(n,μ(A))(n,\mu(A)), and E[1{N>0}/N]≤2/((n+1)μ(A))\E[\mathbf 1\{N>0\}/N]\le2/((n+1)\mu(A)), since 1{N>0}/N≤2/(N+1)\mathbf 1\{N>0\}/N\le2/(N+1) and E[1/(N+1)]≤1/((n+1)μ(A))\E[1/(N+1)]\le1/((n+1)\mu(A)). An empty cell predicts 0 and costs at most ∥m∥∞2\norm m_\infty^2, with probability (1−μ(A))n≤e−nμ(A)≤1/(enμ(A))(1-\mu(A))^n\le e^{-n\mu(A)}\le1/(en\mu(A)). Weighting each cell by μ(A)\mu(A) and summing over the KK cells:

  3. h≍n−1/(d+2)⟹E∫(mn−m)2 dμ=O(n−2/(d+2))h\asymp n^{-1/(d+2)}\qquad\Longrightarrow\qquad\E\int(m_n-m)^2\,d\mu=O\big(n^{-2/(d+2)}\big)

    The variance term grows like h−d/nh^{-d}/n as cells shrink; the squared bias grows like h2h^2 as they widen. Balancing them gives the best side length and the rate:

  4. inf⁡m^ sup⁡m∈Lip(C) E∫(m^−m)2 dμ ≍ n−2/(d+2)\inf_{\hat m}\ \sup_{m\in\mathrm{Lip}(C)}\ \E\int(\hat m-m)^2\,d\mu\ \asymp\ n^{-2/(d+2)}

    Stone (1982) showed that n−2/(d+2)n^{-2/(d+2)} is the minimax rate over Lipschitz regression functions: no estimator does better uniformly over the class. The exponent decays with dd, the curse of dimensionality. Smoother functions do not help a piecewise-constant fit, whose bias inside a cell stays of order hh wherever the gradient is nonzero.

Predict before you look

At the rate n−2/(d+2)n^{-2/(d+2)}, by what factor must nn grow to halve the mean squared error when d=10d=10?

Show the answer

64 ×

For d=10d=10 the error scales as n−1/6n^{-1/6}, so halving it needs 26=642^6=64 times more data. For d=2d=2 the factor is 4; for d=20d=20 it is 211=20482^{11}=2048.

What adaptivity buys. A tree's cells are not regular cubes: greedy splitting concentrates cuts where mm changes fast and on the coordinates it depends on. If mm depends on only s≪ds\ll d coordinates and the splits find them, the effective dimension in the rate is ss, not dd. Stylized forest models make this precise, with rates that depend only on the number of strong features (Biau, 2012; Random Forest Theory). But greedy cuts can also be fooled, as the parity examples of Optimal & Interpretable Trees show, and no general guarantee covers them. Averaging many randomized partitions can even beat the piecewise-constant limit: Mondrian forests attain the minimax rate for functions with Hölder smoothness between 1 and 2, which single trees cannot (Mourtada, Gaïffas & Scornet, 2020).

Instability, and how averaging smooths it

Greedy trees are unstable: the partition depends on the data through a cascade of argmax choices, and near-ties flip under tiny perturbations, changing everything below them. Breiman (1996) made instability precise for model selection, where a procedure is unstable if a small change in the data can produce a large change in the selected predictor, and related the predictive loss from selection to it. The simplest unstable predictor is a hard threshold, the building block of every tree, and Bühlmann & Yu (2002) analyzed exactly such hard decisions to explain why bagging helps. A stylized version of their calculation:

DerivationBagging a threshold
  1. 1{θ^≤x}=1{Z≤c},mean Φ(c),variance Φ(c)(1−Φ(c))\mathbf 1\{\hat\theta\le x\}=\mathbf 1\{Z\le c\},\qquad\text{mean }\Phi(c),\qquad\text{variance }\Phi(c)\big(1-\Phi(c)\big)

    A split point θ^\hat\theta is estimated with n(θ^−θ)/σ≈Z∼N(0,1)\sqrt n(\hat\theta-\theta)/\sigma\approx Z\sim\mathcal N(0,1), and the prediction at xx is 1{θ^≤x}\mathbf 1\{\hat\theta\le x\}. Look within the sampling noise of the true split, at x=θ+c σ/nx=\theta+c\,\sigma/\sqrt n:

  2. Pr⁡∗(θ^∗≤x)≈Φ(n(x−θ^)σ)=Φ(c−Z)\Pr{}^*\big(\hat\theta^*\le x\big)\approx\Phi\Big(\frac{\sqrt n(x-\hat\theta)}{\sigma}\Big)=\Phi(c-Z)

    Bagging averages the predictor over bootstrap resamples. If the bootstrap distribution of θ^∗\hat\theta^* around θ^\hat\theta mimics that of θ^\hat\theta around θ\theta, the bagged prediction is a smooth function of ZZ:

  3. Var⁡[1{Z≤0}]=14⟶Var⁡[Φ(−Z)]=112\Var\big[\mathbf 1\{Z\le0\}\big]=\tfrac14\qquad\longrightarrow\qquad\Var\big[\Phi(-Z)\big]=\tfrac1{12}

    At the split point itself (c=0c=0), Φ(−Z)\Phi(-Z) is uniform on [0,1][0,1], so the variance falls from 1/41/4 to 1/121/12, a factor of 3. Away from the split the gain shrinks (to about 1.3 at c=2c=2), and the bagged mean E Φ(c−Z)=Φ(c/2)\E\,\Phi(c-Z)=\Phi(c/\sqrt2) is a gentler ramp than Φ(c)\Phi(c): bagging trades a little bias for much less variance near the boundary.

  4. f^bag(x)=E∗[f^(x;D∗)]\hat f_{\text{bag}}(\mathbf x)=\E^*\big[\hat f(\mathbf x;\data^*)\big]

    A tree is a cascade of such thresholds, each feeding the next, so its instability compounds, and so does what averaging removes. Bagging is bootstrap smoothing: it replaces a predictor by its bootstrap expectation, which matters for hard, discontinuous decisions and changes little for smooth, stable estimators such as least squares.

Check your understanding

In the stylized threshold model, a point sits exactly at the true split (c=0c=0). By what factor does bagging reduce the variance of the prediction there?

  1. 1: bagging does not change the variance
  2. 2
  3. 3
  4. n\sqrt n
Show the answer

C. 3

Unbagged, the prediction is a fair coin flip, 1{Z≤0}\mathbf 1\{Z\le0\}, with variance 1/41/4. Bagged, it is Φ(−Z)\Phi(-Z), which is uniform on [0,1][0,1] and has variance 1/121/12. The ratio is 3, a constant: the gain does not grow with nn, because both versions vary on the same σ/n\sigma/\sqrt n scale.

Honest trees and inference

Adaptive cells cause a second problem: selection bias. A greedy split is placed where the two children's sample means differ most, so the fitted leaf means overstate the true differences. Even when yy is independent of x\mathbf x, the leaf means of a fitted tree spread out more than the truth warrants, and confidence intervals computed as if the partition had been fixed in advance cover the truth less often than they claim.

Athey & Imbens (2016) introduced honest trees to estimate heterogeneous treatment effects, with splitting rules aimed at effects rather than outcomes. In their simulations, honest estimation gave confidence intervals with close to nominal coverage while adaptive versions undercovered, at a moderate cost in mean squared error from using each half of the data for one task only. Wager & Athey (2018) built random forests from honest trees grown on subsamples and proved that their predictions are consistent and asymptotically normal, with a variance estimate from the infinitesimal jackknife. Random Forest Theory states the theorem, and Causal Inference with Machine Learning puts it to work in causal forests.

Think first The response yy is pure noise, independent of x\mathbf x. You grow a depth-1 tree on 100 points, choosing the threshold that makes the two children's means differ most, then report a textbook 95% interval for each child's mean. Why will these intervals cover the true mean (the same for both children) less than 95% of the time, and how does honesty repair them?

The threshold was chosen to push the two means apart, so the reported means are selected for being extreme: they sit in the tails of their sampling distributions more often than chance allows, and intervals centered on them miss the truth too often. Re-estimating each child's mean on a fresh half of the data, whose responses played no part in choosing the threshold, gives averages of independent draws, and the textbook intervals are valid again, conditional on the split.

Key takeaways

  • Trees are partitioning estimates with data-dependent cells. For plug-in classifiers, L(gn)−L∗≤2 E∣ηn(X)−η(X)∣L(g_n)-L^*\le2\,\E\abs{\eta_n(X)-\eta(X)}, so consistent regression gives consistent classification.
  • Fixed partitions are universally consistent when cells shrink and hold ever more points; data-dependent partitions also need limited combinatorial richness (Lugosi & Nobel, 1996). Greedy CART is only partly understood.
  • For cubic cells of side hh, the error is at most of order h−d/n+h2h^{-d}/n+h^2, optimized at h≍n−1/(d+2)h\asymp n^{-1/(d+2)}: the minimax n−2/(d+2)n^{-2/(d+2)} rate for Lipschitz functions. Adaptivity helps when splits find the relevant coordinates; piecewise constants cannot exploit extra smoothness.
  • Hard thresholds make trees unstable. Bagging smooths 1{Z≤c}\mathbf 1\{Z\le c\} into Φ(c−Z)\Phi(c-Z), cutting the variance at the split point from 1/41/4 to 1/121/12.
  • Honest trees separate partitioning from estimation, removing selection bias; they underpin asymptotically normal forest estimates and causal forests.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

For a partitioning regression estimate with partitions fixed in advance, which pair of conditions gives weak universal consistency?

  1. The cells shrink, and every cell contains at least one training point
  2. The cells shrink, and the number of cells meeting any fixed ball grows more slowly than nn
  3. The number of cells grows like nn, so each holds about one point
  4. The cells stay fixed while nn grows
Show the answer

B. The cells shrink, and the number of cells meeting any fixed ball grows more slowly than nn

Shrinking cells make the bias vanish; having o(n)o(n) cells in any bounded region makes the average number of points per cell grow, so the variance vanishes too.

Question 2

For a CC-Lipschitz regression function on [0,1]d[0,1]^d and a partition into cubes of side hh, what side length minimizes the bound on the mean squared error?

  1. h≍n−1/dh\asymp n^{-1/d}
  2. h≍n−1/2h\asymp n^{-1/2}
  3. h≍(log⁡n)/nh\asymp(\log n)/n
  4. h≍n−1/(d+2)h\asymp n^{-1/(d+2)}
Show the answer

D. h≍n−1/(d+2)h\asymp n^{-1/(d+2)}

The bound is of order h−d/n+h2h^{-d}/n+h^2. Setting the derivative to zero gives hd+2≍1/nh^{d+2}\asymp1/n, and the error is then of order n−2/(d+2)n^{-2/(d+2)}, the minimax rate for Lipschitz functions.

Question 3

Why does bagging help a decision tree much more than it helps ordinary least squares?

  1. Trees are built from hard, discontinuous threshold decisions that flip under small perturbations; averaging over resamples smooths them, while least squares is already a smooth function of the data
  2. Least squares cannot be fitted to bootstrap samples
  3. Bagging reduces bias, and only trees are biased
  4. Trees are fitted by gradient descent, which bagging accelerates
Show the answer

A. Trees are built from hard, discontinuous threshold decisions that flip under small perturbations; averaging over resamples smooths them, while least squares is already a smooth function of the data

Bagging replaces a predictor by its bootstrap average. For a hard threshold this turns a 0/1 jump into a ramp and cuts the variance near the split (by a factor of 3 at the split point in the stylized model). A smooth estimator is nearly linear in the data on the scale of resampling noise, so averaging changes it little.

Question 4

What does honesty, using separate samples to choose a tree's partition and to estimate its leaf values, achieve?

  1. It makes the tree consistent for every distribution
  2. It removes the selection bias of leaf means fitted on the same data that chose the splits, so standard errors and intervals become valid, at the cost of using fewer points for each task
  3. It makes the tree more accurate, because it uses more data
  4. It guarantees the same partition on every resample
Show the answer

B. It removes the selection bias of leaf means fitted on the same data that chose the splits, so standard errors and intervals become valid, at the cost of using fewer points for each task

Conditional on a partition chosen from one half, the leaf means from the other half are averages of independent responses, so the usual variance formulas apply. Wager & Athey (2018) build asymptotically normal forests on this property.

Further reading

  • L. Devroye, L. Györfi & G. Lugosi, A Probabilistic Theory of Pattern Recognition (Springer, 1996).
  • L. Györfi, M. Kohler, A. Krzyżak & H. Walk, A Distribution-Free Theory of Nonparametric Regression (Springer, 2002).
  • G. Lugosi & A. Nobel, "Consistency of data-driven histogram methods for density estimation and classification," Annals of Statistics 24(2), 687–706 (1996).
  • P. Bühlmann & B. Yu, "Analyzing bagging," Annals of Statistics 30(4), 927–961 (2002).
  • S. Wager & S. Athey, "Estimation and inference of heterogeneous treatment effects using random forests," Journal of the American Statistical Association 113(523), 1228–1242 (2018).