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

Model Trees (M5)

A model tree puts a linear regression in every leaf instead of a constant, so a few splits can capture piecewise-linear behaviour that would need dozens of CART steps, and predictions follow trends instead of going flat. Quinlan's M5 (1992) and Wang and Witten's M5′ (1997) grow the tree with a standard-deviation-reduction criterion, fit linear models at the nodes, prune bottom-up with a pessimistic error estimate, and smooth predictions along the path. This page covers the M5 recipe, its pruning and smoothing formulas, and a weakness: it chooses splits as if leaves were constant. In the exercises you implement M5 and check it on a piecewise-linear target; then you compare SDR splits with model-based splits, CART and a global linear model, both in range and when extrapolating.

Level 0: Foundation

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

A line in every leaf

A motor’s power draw rises gently with speed, then steeply past some speed. A regression tree with constant leaves needs a long staircase to follow two slopes. A model tree splits once at the kink and fits a straight line in each piece. Fewer splits, smoother predictions, and beyond the data it keeps following the last trend instead of flattening out.

Model trees: put a line in every leaf
no data
leaves 2 · RMSE to the true curve: in range 0.095, beyond the data 0.061
With linear leaves one split at the kink (depth 1) already matches the curve, and the last segment's slope carries on into the shaded no-data region. Constant leaves need many steps to follow the slopes and go flat beyond the data, so their extrapolation error grows with distance.
Why engineers care

Many physical relationships are piecewise linear: regimes of a power curve, saturation, gear ranges, phases of flight. Model trees capture them compactly and readably (“if speed is above 4, power ≈ 2 + 1.1·(speed − 4)”), and they degrade more gracefully outside the training range than constant-leaf trees, a real concern for systems that meet new operating points.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Model-tree leaves contain…
  2. 2. Beyond the training data, model trees…
  3. 3. For a piecewise-linear target, model trees usually need…

Level 1: Beginner

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

M5’s formulas by hand

Splitting: standard-deviation reduction. SDR = sd(T) − Σ (|T_i|/|T|)·sd(T_i).

  • Targets 1, 1, 5, 5 split into (1, 1) and (5, 5): sd(T) = 2 and both children have sd 0, so SDR = 2.
  • Splitting into (1, 5) and (1, 5) gives SDR = 2 − 2 = 0.

Pruning: pessimistic error. M5 estimates a model’s error on new data as mean|residual| × (n + v)/(n − v), with v the number of parameters. With n = 6 residuals of size 0.1 and v = 2 (intercept and slope):

0.1 × 8/4 = 0.2.

A subtree is replaced by its node’s linear model if that estimate is no worse than the subtree’s.

Smoothing. On the way from a leaf back to the root, each node blends: p′ = (n·p + k·q)/(n + k), with p the prediction coming up from the child, q the node’s own linear model, n the child’s training cases and k = 15.

  • If a leaf with n = 15 predicts 2 and its parent’s model says 4, then p′ = (30 + 60)/30 = 3.
  • With n = 135 the leaf dominates: p′ = (270 + 60)/150 = 2.2.

The steps in plain English:

  1. Grow a tree by choosing splits that most reduce the targets’ standard deviation.
  2. Fit a linear model at every node, using the features tested in its subtree in M5 (all features in this page’s code).
  3. Prune bottom-up wherever the node’s linear model has pessimistic error no worse than its subtree’s.
  4. Predict with the leaf’s model, smoothed toward its ancestors’ models.
📝 Quick check (Level 1)
0/3 answered
  1. 1. SDR for targets (1, 1, 5, 5) split into (1, 1) and (5, 5)?
  2. 2. Pessimistic factor (n + v)/(n − v) for n = 10, v = 2?
  3. 3. Smoothing gives more weight to the leaf when…

Level 2: Intermediate

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

M5, M5′ and model-based splitting

M5 (Quinlan, 1992). SDR splitting, linear models at nodes (with greedy attribute dropping), error-based pruning and smoothing.

M5′ (Wang and Witten, 1997) adds handling of nominal attributes (binary indicators ordered by target mean), missing values (surrogate splitting on the class) and cleaner pruning. It is available as M5P in Weka.

The split-criterion problem. SDR measures how well a constant would fit each child, but M5 then fits lines. A split that separates two regions with different slopes but similar means has low SDR and is missed. Meanwhile steep slopes inside a region inflate the standard deviation and attract splits on the sloped feature. Exercise 2 shows the cost: on a target whose regimes differ in slope but not in mean, SDR splits used 6.8 leaves where 2 suffice.

Model-based splitting fixes this by scoring a split by the children’s linear-fit residuals. It is costlier, an O(p²) or O(p³) fit per candidate, so it is often done on a grid. GUIDE (Loh, 2002) and MOB (Zeileis, Hothorn and Hornik, 2008) use statistical tests of parameter instability to pick split variables. Cubist, the commercial descendant of M5, combines rules, linear models, boosting and nearest-neighbour corrections.

Related methods.

Method Leaves Splits chosen by
CART constants SSE
M5 / M5′ linear models SDR (constant criterion)
GUIDE / MOB linear (or GLM) models parameter-instability tests
LightGBM linear_tree linear models in each leaf gradient-boosting gain
🐍 Exercise 1: an M5 model tree
Implement node linear models, SDR splitting, M5's pessimistic error pruning and smoothed prediction; verify on a two-regime linear target with a jump that it splits once at the break, fits accurately, extrapolates the leaf trends, and prunes a purely linear target to a single model.
📝 Quick check (Level 2)
0/3 answered
  1. 1. SDR scores a split as if leaves were…
  2. 2. Model-based splitting scores a split by…
  3. 3. Weka's M5′ implementation is called…

Level 3: Advanced

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

Theory

Approximation power. A function that is piecewise linear on k axis-aligned regions is represented exactly by a model tree with k leaves, while constant leaves need an ever-finer staircase. For a smooth f, a constant-leaf partition with cells of width h has bias O(h); linear leaves reduce this to O(h²) (local linear versus local constant fitting). That is why model trees reach a given accuracy with far fewer leaves.

Extrapolation. A linear leaf extrapolates its fitted plane. This is good when the trend continues (exercise 2: error 0.04 against CART’s 0.79) and dangerous when it does not, for example saturation beyond the data. Constant leaves are conservative but always wrong for trending targets.

Variance. Each linear leaf estimates p + 1 parameters, so leaves need more data. Pruning with the (n + v)/(n − v) factor and smoothing toward ancestor models are M5’s variance controls. Smoothing is a crude shrinkage that matters most for small leaves.

Interview questions.

  • Why might M5 choose a poor split? SDR assumes constant leaves, so it is blind to slope changes and attracted by steep within-region trends. Model-based or test-based splitting (GUIDE, MOB) fixes this.
  • When prefer a model tree to gradient boosting? Small or medium data with clear regimes, a need for interpretable piecewise-linear rules, or likely extrapolation.
📝 Quick check (Level 3)
0/3 answered
  1. 1. Linear leaves reduce the bias for smooth f from O(h) to…
  2. 2. Linear-leaf extrapolation is risky when…
  3. 3. M5's smoothing acts like…

Level 4: Expert

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

Choosing splits for linear leaves

History.

  • Quinlan’s M5 (1992) introduced model trees.
  • Wang and Witten (1997) published M5′.
  • Quinlan’s Cubist (commercial, open-sourced 2011) extended M5 with rules, boosting (“committees”) and instance-based corrections.
  • Loh’s GUIDE (2002) and Zeileis et al.’s MOB (2008) gave statistically principled model-based splitting.
  • LightGBM added linear trees in 2020.

Exercise 1.

  • On a two-regime target with a jump at x₀ = 0, M5 split once on x₀ at 0.002 with 2 leaves and test RMSE 0.007.
  • Outside the data, at (5, 0) and (5, 4), it predicted −3.03 and −1.04 (true −3 and −1).
  • A purely linear target was pruned back to a single linear model.

Exercise 2. Setup: target f = 1 + 2x₁ for x₀ below 0 and 3 − x₀ otherwise, a change of regime with no jump in the overall mean. Noise σ = 0.1, n = 300, 5 repetitions. Extrapolation means x₀ in [2, 3].

Model RMSE in range RMSE extrapolating leaves
CART (constant leaves) 0.468 0.791 15.4
M5 (SDR splits, linear leaves) 0.337 0.154 6.8
model-based splits (linear leaves) 0.167 0.037 2.2
global linear regression 1.319 2.000 1
  • Linear leaves beat constant leaves on every measure. In range, extrapolating and in size.
  • The split criterion mattered as much as the leaf model. SDR, blind to slope changes, used 6.8 leaves and still had twice the in-range error of model-based splitting, which found the regime change with about 2 leaves.
  • Model-based splitting extrapolated almost perfectly here (0.037), because the right-hand regime is exactly linear in x₀.
  • Caveat: its remaining in-range error comes from thresholds on a 39-point grid straddling the break.
🐍 Exercise 2 (research): split criteria for model trees
On a two-regime target, compare CART, M5 with SDR splits, a model tree with linear-residual (model-based) splits and global linear regression: RMSE in range, RMSE when extrapolating, and number of leaves (5 repetitions).

Model trees in AI, robotics and aerospace

  • Power and thermal models by regime: linear in each operating mode, with readable breakpoints.
  • Performance tables (fuel flow against altitude and Mach) as compact piecewise-linear models.
  • Software effort and cost estimation: a classic M5 application.
  • Boosting with linear leaves (LightGBM linear_tree) for smoother, trend-aware ensembles.

References

  1. J. R. Quinlan (1992). “Learning with continuous classes.” Proceedings of the 5th Australian Joint Conference on AI.
  2. Y. Wang, I. H. Witten (1997). “Inducing model trees for continuous classes.” ECML Poster Papers.
  3. W.-Y. Loh (2002). “Regression trees with unbiased variable selection and interaction detection.” Statistica Sinica 12.
  4. A. Zeileis, T. Hothorn, K. Hornik (2008). “Model-based recursive partitioning.” JCGS 17(2).
  5. M. Kuhn, K. Johnson (2013). Applied Predictive Modeling, chapter 8 (Cubist). Springer.