Foundations to Frontier
Tests
D. Classical Machine Learning › D6 Decision Trees

CART Regression Trees (Variance Reduction)

A regression tree predicts a number with a staircase: each binary split is chosen to make the two child groups as homogeneous as possible, measured by the sum of squared errors around each group's mean, and each leaf predicts its mean. With prefix sums every candidate threshold is scored in linear time. This page covers the variance-reduction criterion, its fast computation, leaf predictions (mean for squared loss, median for absolute loss), why trees are flat outside the data, and the bias-variance trade-off as depth grows, the reason trees are pruned or ensembled. In the exercises you implement a regression tree with prefix-sum split search; then you measure bias and variance against depth at two noise levels.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Predicting a number with a staircase

To predict battery temperature from current draw, a regression tree asks “Is the current ≤ 2.1 A?” and then predicts the average temperature of past cases that answered the same way. More questions give finer steps. Each split is chosen to make the two groups as consistent as possible, with the smallest spread around their means. A few steps capture the trend; too many steps start tracing the noise.

Regression trees: staircases, bias and variance
leaves 8 · training MSE 0.092 · MSE against the true curve 0.113
Shallow trees are coarse staircases (high bias). Deep trees drive the training error toward 0 by giving single points their own leaves; the redrawn fits then disagree wildly (high variance), and the error against the true curve rises again, faster when the noise is larger. A minimum leaf size averages several points per leaf and tames the variance.
Why engineers care

Regression trees are the workhorse inside random forests and gradient boosting, which dominate tabular regression for loads, temperatures, remaining useful life and cost estimation. They handle mixed feature types and interactions without manual feature engineering, but they cannot extrapolate beyond the training range, which matters for any system that will see new operating conditions.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A regression tree leaf predicts…
  2. 2. Splits are chosen to minimise…
  3. 3. Very deep trees mostly suffer from…

Level 1: Beginner

★★☆☆☆ Basic⏱ 25 minSecondary-school mathematics: arithmetic and elementary algebra.

One split by hand

Data: x = 1, …, 6 with y = 1.0, 1.2, 0.8, 5.0, 5.2, 4.8.

Parent: mean 3.0, SSE = Σ(y − 3)² = 4 + 3.24 + 4.84 + 4 + 4.84 + 3.24 = 24.16.

Cut at x ≤ 3.5:

  • Left (1.0, 1.2, 0.8): mean 1.0, SSE = 0 + 0.04 + 0.04 = 0.08.
  • Right (5.0, 5.2, 4.8): mean 5.0, SSE = 0.08.
  • Decrease = 24.16 − 0.16 = 24.0.

Shortcut with sums. SSE = Σy² − (Σy)²/n, so the decrease equals S_L²/n_L + S_R²/n_R − S²/n.

  • Here S_L = 3, S_R = 15, S = 18: decrease = 9/3 + 225/3 − 324/6 = 3 + 75 − 54 = 24.
  • With cumulative sums over the sorted x, every cut is scored in O(1) after sorting.

Prediction: 1.0 for x ≤ 3.5 and 5.0 otherwise. For x = 100, still 5.0: trees are flat outside the data.

The steps in plain English:

  1. For each feature, sort by value and sweep the cut, using running sums to score each cut’s SSE decrease.
  2. Split on the best cut overall, if it beats the minimum decrease and leaves enough points on each side.
  3. Recurse until the depth limit, minimum leaf size or minimum decrease stops it.
  4. Each leaf predicts the mean of its points.
📝 Quick check (Level 1)
0/3 answered
  1. 1. SSE of (1, 3)?
  2. 2. Decrease formula uses…
  3. 3. Prediction for x far beyond the training range?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.

The criterion and its variants

Squared loss (CART default). Minimising child SSE is maximising the decrease in variance weighted by node size. Leaves take the mean.

Absolute loss. Minimise Σ|y − median| per child, and leaves take the median. This is robust to outliers but slower (running medians are needed).

Poisson or Huber losses suit counts and heavy tails (available in scikit-learn and boosting libraries).

Variance and Gini. For class indicators, the total variance is Σ p_c(1 − p_c), which is Gini impurity. CART classification is variance reduction on one-hot targets.

Size control.

  • max_depth and max_leaf_nodes cap complexity;
  • min_samples_leaf averages several points per leaf (reducing variance);
  • min_impurity_decrease rejects tiny gains;
  • cost-complexity pruning (next pages) chooses the subtree by CV.

Limitations.

  • Piecewise-constant fits make jagged approximations to smooth functions.
  • There is no extrapolation beyond the data.
  • Trees are high-variance and unstable: small data changes can flip the root split.
  • Ensembles (bagging, forests, boosting) exist to fix exactly these.
from sklearn.tree import DecisionTreeRegressor
reg = DecisionTreeRegressor(criterion="squared_error", min_samples_leaf=10).fit(X, y)
🐍 Exercise 1: a regression tree with prefix-sum splits
Implement SSE, the O(n) best-split scan via prefix sums (checked against brute force), recursive fitting and prediction; recover a known step function, confirm predictions are flat outside the data, and verify that two-class Gini equals the total variance of class indicators.
📝 Quick check (Level 2)
0/3 answered
  1. 1. With absolute-error loss, leaves predict…
  2. 2. min_samples_leaf mainly reduces…
  3. 3. Trees are 'unstable' meaning…

Level 3: Advanced

★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.

Theory

Bias-variance decomposition. At a test point, E[(ŷ − y)²] = (E ŷ − f)² + Var ŷ + σ².

  • Deeper trees have smaller cells, so bias falls (the step approximation improves).
  • But each leaf averages fewer points, so variance rises toward σ² per leaf, plus the variance from unstable split locations.

The optimal depth balances the two, and it shrinks as noise grows. Exercise 2: the best depth was 9 at σ = 0.3 and 6 at σ = 0.6.

Approximation rates. For a Lipschitz f in d dimensions, a regular partition into cells of width h has bias O(h²) and variance O(σ²/(n·h^d)). Optimising gives MSE of order n^(−2/(d+2)), the curse of dimensionality for local averaging (Györfi et al., 2002). Adaptive trees do better when f varies along few directions.

Instability. The split threshold is a discontinuous function of the data, which is why bagging trees reduces variance so effectively (Breiman, 1996).

Interview questions.

  • Why can’t a tree model y = 2x outside the training range? Leaves are constants, so beyond the last cut the prediction is the edge leaf’s mean. Use linear models, model trees (M5) or features that encode the trend.
  • min_samples_leaf or max_depth? min_samples_leaf adapts to local data density and directly controls leaf variance. It often generalises better (exercise 2 at σ = 0.6).
📝 Quick check (Level 3)
0/3 answered
  1. 1. More noise makes the optimal tree depth…
  2. 2. Bagging helps trees mainly by reducing…
  3. 3. Local averaging's error rate n^(−2/(d+2)) shows…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

Bias and variance against depth

History.

  • Morgan and Sonquist’s AID (1963) was the first regression tree, built for survey analysis.
  • Breiman et al.’s CART (1984) added cost-complexity pruning and consistency results.
  • Quinlan’s M5 (1992) put linear models in the leaves (see model trees).
  • Breiman’s bagging (1996) and random forests (2001) turned unstable trees into strong regressors.
  • Friedman’s gradient boosting (2001) used small regression trees as its base learner.

Exercise 1.

  • The best cut is x ≤ 3.5, with SSE decrease 24.0.
  • Prefix-sum scoring matched brute force on 10 random problems.
  • A depth-2 tree recovered a two-feature step function (first split on x₀ at 0.397, then x₁).
  • Predictions are flat outside the data.

Exercise 2. Setup: f = sin(3x₀) + x₁², n = 200, and 30 training sets per noise level. The table shows expected test MSE = bias² + variance + σ².

Model σ = 0.3 σ = 0.6
depth 1 (stump) 0.874 1.152
depth 4 0.480 0.792
best depth 0.286 (depth 9) 0.708 (depth 6)
depth 10 0.289 0.816
depth 10, min leaf 10 0.361 0.674
linear model 1.001 1.275
  • Bias fell steadily with depth, from 0.67 at depth 1 to about 0.02–0.03 at depth 10.
  • Variance rose with depth at σ = 0.6 (0.28 at depth 5 to 0.43 at depth 10). Doubling the noise moved the best depth from 9 to 6.
  • A minimum leaf size of 10 helped only at the higher noise level. At σ = 0.3 its extra bias (0.13 against 0.02) outweighed its variance savings.
  • The linear model had tiny variance (about 0.02) but huge bias (about 0.89). It cannot represent the sine.
🐍 Exercise 2 (research): bias and variance of regression trees
For σ in {0.3, 0.6}, fit trees of depth 1–10 (plus a min-leaf-10 tree and a linear model) to 30 independent training sets of a 2-D function; decompose expected test MSE into bias² and variance and find the best depth.

Regression trees in AI, robotics and aerospace

  • Inside ensembles for load, temperature and remaining-useful-life regression.
  • Piecewise operating maps: fuel flow or power draw by flight regime, as readable lookup tables.
  • Fast surrogates for planners: a tree is microseconds to evaluate.
  • Caution: trees will not extrapolate to new altitudes, speeds or temperatures; check coverage of the operating envelope.

References

  1. L. Breiman, J. H. Friedman, R. A. Olshen, C. J. Stone (1984). Classification and Regression Trees. Wadsworth.
  2. J. N. Morgan, J. A. Sonquist (1963). “Problems in the analysis of survey data, and a proposal.” JASA 58.
  3. L. Györfi, M. Kohler, A. Krzyżak, H. Walk (2002). A Distribution-Free Theory of Nonparametric Regression. Springer.
  4. L. Breiman (1996). “Bagging predictors.” Machine Learning 24.
  5. T. Hastie, R. Tibshirani, J. Friedman (2009). The Elements of Statistical Learning, 2nd ed., sections 7.3 and 9.2. Springer.