Classical machine learning
Decision Trees: Recursive Partitioning
Understand greedy tree growth, split criteria, classification and regression leaves, categorical handling, support, and extrapolation limits.
By the end you can
- Explain how a decision tree recursively partitions feature space
- Compare classification and regression split objectives and leaf predictions
- Interpret a tree path without making causal claims
- Identify overfitting, category-encoding, support, and extrapolation risks
A decision tree turns feature space into a hierarchy of regions
Each internal node asks a threshold or category question, sends the row down one branch, and continues until a leaf produces a prediction. The tree learns the questions and their order from data.
This creates a piecewise-constant model: every row in one leaf receives the same class distribution or numeric estimate. One leaf, one answer.
That is not a classroom abstraction. Children who arrive at an emergency department after head trauma are sorted by exactly this object. The partition was grown from 42,412 children enrolled at 25 North American emergency departments, and each region carries one prediction: whether the child is at very low risk of clinically-important brain injuries. The Pediatric Emergency Care Applied Research Network published it. This lesson uses that tree, and the papers that later re-measured it, in place of hypothetical ones.
A tree is a partitioning algorithm whose rules are readable only in the context of the path and the training data.
Case
A 1986 chess tree held 84 per cent accuracy on positions it had never seen
1.4 million chess positions, described by 49 binary-valued attributes, collapse to 715 distinct objects, divided 65% : 35% between two classes. A tree that classified all 715 correctly took about 150 nodes.
Ross Quinlan reported that in 1986, in the paper that introduced ID3. The number that matters is not the 150 nodes. It is what happened when trees were grown from randomly chosen training sets holding only 20% of those 715 objects: they “correctly classified over 84% of the unseen objects”. A second version of the same domain used 39 attributes and left 551 distinct objects. Training sets of the same 20% gave “decision trees of almost identical accuracy”.
The partition generalised. The readable rules came with it, not instead of it.
Visual
The anatomy of one fitted tree
The same feature may appear at several nodes, because its useful threshold depends on the path already taken.
Size is not fixed by the vocabulary. Quinlan needed about 150 nodes to classify all 715 chess objects correctly. The PECARN rules examined later in this lesson reach their leaves in six conditions. Root, internal node, branch, leaf and path are the same five parts in both cases. How many of each there are is a modelling decision, not a property of the method.
Root node
Contains the full training subset before any split.
Internal node
Tests one feature condition and partitions the current subset.
Branch
Represents the outcome of a split condition.
Leaf
Stores a prediction and the local training composition.
Path
Combines several conditions into one region of feature space.
Greedy growth answers an NP-complete problem, and its cost has been measured
Classification trees often choose splits that reduce impurity such as Gini or entropy. Regression trees reduce squared or absolute error. Either way the search is greedy: it takes the best split available now, without jointly optimizing the final tree. A locally attractive split can block a better later structure. Growth and pruning therefore work together.
Greed here is a decision, not an oversight. Hyafil and Rivest settled that in 1976, and their title is the result: “Constructing Optimal Binary Decision Trees is NP-Complete”. The exhaustive alternative is unavailable at any interesting size. That is still the reason production libraries give for how they grow trees. Listed under the disadvantages of decision trees, the scikit-learn documentation says: “The problem of learning an optimal decision tree is known to be NP-complete under several aspects of optimality and even for simple concepts. Consequently, practical decision-tree learning algorithms are based on heuristic algorithms such as the greedy algorithm where locally optimal decisions are made at each node.” Quinlan said as much about ID3 in 1986. It “has generally been found to construct simple decision trees, but the approach it uses cannot guarantee that better trees have not been overlooked”.
What the greedy step does to a tree has a mechanism. Hu and colleagues stated it in 2019: “CART and C4.5 grow decision trees from the top down without backtracking, which means that if a suboptimal split was introduced near the top of the tree, the algorithm could spend many extra splits trying to undo the mistake it made at the top, leading to less-accurate and less-interpretable trees.” The same paper then presented the first published optimal sparse binary-split trees for the COMPAS and FICO datasets. Note what is being claimed. Not that the greedy tree is wrong, but that it spends depth repairing an early choice. Depth is the thing that made the tree readable.
How much is overlooked has been measured. Bertsimas and Dunn built optimal classification trees in 2017, once mixed-integer solvers had caught up, and benchmarked them against CART “on a sample of 53 datasets from the UCI machine learning repository”. They report “average absolute improvements over CART of 1–2 and 3–5% for OCT and OCT-H, respectively, across all datasets depending on the depth of tree used”, and that “across all 53 datasets, OCT closes the gap between CART and Random Forests by about one-sixth, and OCT-H by about half”. The greedy step costs a point or two of accuracy for the univariate variant, three to five for the hyperplane one. That is a published number, not a suspicion.
Comparison
Classification and regression trees share mechanics but not leaf meaning
Both partition space. Each then summarizes outcomes within its leaves.
The split objective is also where an asymmetric cost enters. PECARN did not ask its search to minimise total error. The rules were derived with a deliberate 500-to-1 relative misclassification cost, so the two kinds of mistake were never weighed the same. A class weight is not a post-hoc adjustment to the output. It changes which splits the search prefers while the tree is still being grown.
Classification tree
Leaves store class counts or distributions.
- Splits reduce class impurity
- Thresholds create axis-aligned regions
- Probabilities can be coarse in small leaves
- Class weights alter split incentives
Regression tree
Leaves store a numeric summary, commonly a mean.
- Splits reduce within-leaf loss
- Predictions are stepwise constant
- Cannot extrapolate beyond leaf summaries
- Outliers can influence squared-error splits
Multi-output tree
Leaves summarize several related targets.
- One partition serves multiple outputs
- Targets compete for split improvements
- Can share structure efficiently
- Requires careful scale and loss design
Example
One real path, and the 3800 children who reached its leaf
The tree in this section is not invented. Kuppermann and colleagues wrote down how they grew it, in the Methods of their 2009 Lancet paper: “We derived the rules with binary recursive partitioning (CART PRO 6.0; San Diego, CA, USA, Salford Systems).” Splits were scored on Gini. Structure was chosen by ten-fold cross-validation. The search ran under a 500-to-1 relative misclassification cost. Two rules came out — one for children aged 2 years and older, one for children under 2 years — each a short path of six conditions ending in a leaf.
Read the figures below for what they are. They say how children routed through this partition, and how often the leaf that received them was right. They do not say why a head injury occurs. No arrangement of the same numbers would.
- Growth: binary recursive partitioning over 42,412 children enrolled at 25 North American emergency departments, splits scored by Gini, structure selected by ten-fold cross-validation.
- Cost: a deliberate 500-to-1 relative misclassification cost, so the split search was told before it began that the two kinds of error are not worth the same amount.
- Leaf, children aged 2 years and older: in the validation population the negative predictive value was 3798/3800 — 99.95%, 95% CI 99.81–99.99 — with sensitivity 61/63, 96.8% (89.0–99.6). The denominator is the support, and 3800 is why the interval is narrow.
- Leaf, children under 2 years: 1176/1176, 100.0% (99.7–100.0), with sensitivity 25/25, 100% (86.3–100.0). A leaf frequency of exactly one still rests on 25 positive cases, which is why that interval runs down to 86.3 while the other runs down to 89.0.
- Independent re-measurement: an Australasian cohort of 20,137 children, reported by Babl and colleagues, gave validation sensitivities of 100.0% (95% CI 90.7–100.0; 38/38) for the under-2 rule and 99.0% (94.4–100.0; 97/98) for the 2-and-over rule. The same readable path, re-scored by a different group on a different cohort. Still a description of association within a partition.
Analogy
A choose-your-own-route map learned from examples
A map repeatedly asks one question — bridge open, road steep, vehicle tall — and sends travelers toward a destination estimate. Each answer narrows the region in which the final recommendation applies. Six questions and a recommendation is the shape of the PECARN rule as much as of the map.
A road map is surveyed. Tree questions are chosen greedily from noisy data, and may exploit arbitrary thresholds. A readable route is not automatically a stable or causal explanation. 3798/3800 tells you the route sorted those children well. It does not tell you what produced the injuries.
A path explains how the fitted tree routed a row, not why the world produced the outcome.
Steps
Grow a tree as a controlled diagnostic model
Use constraints to learn structure without memorizing individual rows.
Each of these steps is a decision someone has already published a default for. PECARN fixed its structural limits by ten-fold cross-validation, and its split incentives by a 500-to-1 relative misclassification cost. The evaluation step is the one most often done wrongly. Ploton and colleagues put a number on the difference between slicing the held-out data at random and slicing it away from the training rows: R² = 0.53 became R² = 0.14 on the same model.
1. Prepare valid features
Handle leakage, missingness, categories, and time before tree growth.
2. Fit a shallow baseline
Expose major thresholds and interactions first.
3. Tune structural limits
Cross-validate depth, leaf size, split size, and pruning.
4. Inspect paths and leaves
Read support counts, class mix, and feature ranges.
5. Test threshold stability
Compare splits across folds and nearby samples.
6. Evaluate relevant slices
Check rare classes, boundaries, and unsupported combinations.
Key idea
A pure leaf is a training artefact: 0.08789 in training, 0.10211 in test
A leaf with two positive examples and no negatives reports a training frequency of one. The estimate is extremely uncertain. Deep trees produce many such local summaries, and they can look confident while generalizing poorly.
There are two reasons, and Zadrozny and Elkan named them in 2001, in a section called “Deficiencies of decision tree methods”. The first is high bias: growth deliberately makes leaves homogeneous, which pushes the observed frequencies toward 0 and 1. The second they state directly — “High variance: When the number of training examples associated with a leaf is small, observed frequencies are not statistically reliable.”
They then measured it on the KDD'98 contest data. An unpruned C4.5 tree scored a mean squared error of 0.08789 on the training set and 0.10211 on the test set. Curtailment stops at any node holding too few examples rather than growing on into the tiny leaves. It scored 0.09508 on training and 0.09535 on test: a worse training number and a better test one. Bagged curtailment gave the best test MSE of the set, 0.09515. The gap between 0.08789 and 0.10211 is the exact size of what a pure leaf was promising and could not deliver.
The same diagnosis arrived independently in 2005, from Niculescu-Mizil and Caruana, who evaluated ten algorithms on eight problems: “Unfortunately, a single decision tree has high variance and this variance affects it's calibration.”
Minimum leaf size and probability calibration matter when outputs drive risk decisions.
Leaf purity without adequate support is memorization dressed as certainty.
One encoding choice moves the search from 2^(k−1)−1 splits to k−1
Some implementations require one-hot or ordinal encodings, while others search category partitions directly. The size of that difference is exact rather than rhetorical. For a nominal predictor with k categories the standard search evaluates all 2^(k−1)−1 two-way partitions. For binary classification and regression there is a shortcut, and it is not an approximation: order the categories by the outcome — by the proportion of 1s for a binary outcome, by the increasing outcome mean for regression — and treat them as ordinal. Exactly the same splits come out. Wright and König put the consequence in one line: “This reduces computational complexity because only k − 1 splits have to be considered for a nominal predictor with k categories.” The result is older than their 2019 paper, which credits Fisher 1958, Breiman et al. 1984 and Ripley 1996. LightGBM's official documentation implements it, and reports that it “often performs better than one-hot encoding”. One-hot encoding fragments a categorical decision across many nodes. Arbitrary ordinal codes impose an order the categories do not have.
Unknown categories at inference are not a documentation chore either. They are a named defect with a measured frequency. Au named it the absent levels problem in 2018 and defined it: “This problem occurs whenever there is an indeterminacy over how to handle an observation that has reached a categorical split which was determined when the observation in question's level was absent during training.” He showed that Breiman and Cutler's original random forests FORTRAN code and the randomForest R package systematically bias predictions in exactly that situation.
A separate group then measured how often it actually bites. On Campylobacter source-attribution data, 16% of individual tree predictions under PCO-encoding and 22% under CA and CA-unbiased encoding used at least one absent level. Average misclassification error ran from 23.2%±1.2% to 27.0%±1.2% across the three encodings. Roughly one tree vote in five was cast on an indeterminacy.
The alternative is to write the routing rule down where users can read it, as LightGBM does: “At predict() time, categories not seen during training will be treated as missing values.”
Tree invariance to monotonic numeric scaling does not make every encoding semantically valid.
R² = 0.53 became R² = 0.14 when the test data moved away from the training data
A regression tree predicts leaf summaries. It therefore does not extend a learned slope beyond the observed feature support. This can be safe in some bounded tasks and poor in forecasting trends. Unsupported feature combinations can still land in a leaf, because every path ends somewhere.
What that costs has been measured on forest-inventory data covering 11.8 million trees in central Africa. Ploton and colleagues trained a random forest there and scored it twice. Under conventional random cross-validation it reached R² = 0.53, with an RMSPE of 56.5 Mg ha⁻¹ (19%). Under spatial 44-fold cross-validation, which scores the model on blocks it was not trained on, the same model reached R² = 0.14, with an RMSPE of 77.5 Mg ha⁻¹ (26%). Their 2020 abstract in Nature Communications says it without hedging: “A standard nonspatial validation method suggests that the model predicts more than half of the forest biomass variation, while spatial validation methods accounting for SAC reveal quasi-null predictive power.”
This is not one group's unlucky dataset. Stock reached the same conclusion independently in 2025, on a marine remote sensing case study, finding that 10-fold cross-validation underestimated prediction errors by 5% to 54% depending on the model and metric. Add range and support checks around the tree. Then choose the validation split so that it asks the question deployment will ask.
A complete partition always returns an answer, even when deployment enters an empty region of the training data.
Key takeaways
- A decision tree creates a hierarchy of axis-aligned regions and assigns one leaf prediction to each region; the PECARN rules are that structure, grown from 42,412 children at 25 North American emergency departments.
- Split search is greedy because optimal trees are NP-complete to construct, and the price is published: across 53 UCI datasets, Bertsimas and Dunn report “average absolute improvements over CART of 1–2 and 3–5% for OCT and OCT-H, respectively, across all datasets depending on the depth of tree used”.
- Classification leaves summarize class composition and regression leaves summarize numeric outcomes, and an asymmetric cost such as PECARN's 500-to-1 changes which splits the search prefers while the tree is still growing.
- A readable path explains routing, not cause: a negative predictive value of 3798/3800 says the partition sorted those children well, and says nothing about why the injuries happened.
- Leaf frequencies are not probabilities — an unpruned C4.5 tree moved from 0.08789 MSE in training to 0.10211 in test, while curtailment scored 0.09508 and 0.09535, and bagged curtailment reached 0.09515.
- Categorical routing (2^(k−1)−1 partitions versus k−1), absent levels used by 16–22% of individual tree predictions, and R² falling from 0.53 to 0.14 under spatial validation all require explicit, documented deployment behavior.