Sub topic 14
Limitations of single trees
This chapter assumes you can fit a scikit-learn DecisionTreeClassifier, know why deep trees overfit, and have seen cross-validation and pruning. Pruning and tuning reduce a tree's problems, but several limits remain.
High variance
A small change in the training data can produce a very different tree. Splits near the root decide everything below them. If a different sample changes the first split, every later split changes too. This is why unpruned trees overfit, and pruning only partly fixes it.
The code below fits trees to bootstrap resamples of the iris data. A bootstrap resample is a sample drawn with replacement, the same size as the original.
import numpy as np
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
data = load_iris()
X, y = data.data, data.target
rng = np.random.RandomState(0)
for i in range(5):
idx = rng.choice(len(X), size=len(X), replace=True)
tree = DecisionTreeClassifier(random_state=0).fit(X[idx], y[idx])
feature = data.feature_names[tree.tree_.feature[0]]
threshold = tree.tree_.threshold[0]
print(f"sample {i}: root splits on {feature} at {threshold:.2f}, "
f"depth {tree.get_depth()}, leaves {tree.get_n_leaves()}")Compare the root split and the tree size across samples. On iris, several features separate one class equally well, so the choice among them can shift from sample to sample.
Greedy search
Each split is chosen for its immediate impurity decrease, with no look-ahead. The final tree is therefore not guaranteed to be the best tree. A split that looks weak alone but enables a strong split below it can be missed. XOR-style patterns are the classic case. Neither feature alone reduces impurity, so the greedy search sees no useful first split.
Axis-aligned, piecewise-constant boundaries
Every split tests one feature against one threshold. A diagonal boundary such as x1 > x2 must be approximated by a staircase of many splits. Regression trees have a related limit. Each leaf predicts a constant, so the fitted function is a step function. It also cannot extrapolate. For inputs beyond the training range, a regression tree returns the value of the nearest edge leaf.
Other weaknesses
| Limitation | Effect | Partial remedy |
|---|---|---|
| High variance | Unstable structure and predictions | Pruning, ensembles |
| Greedy splits | Suboptimal trees, missed interactions | Ensembles with randomized splits |
| Axis-aligned splits | Staircase approximation of diagonal boundaries | Feature engineering, such as adding `x1 - x2` |
| No extrapolation | Flat predictions outside the training range | Use a different model family |
| Imbalanced classes | Majority class dominates leaf impurity | `class_weight="balanced"` |
| Biased importances | Impurity-based importance favors high-cardinality features | Permutation importance |
How ensembles respond
The next chapter covers ensembles. Here is the idea in brief. Averaging many high-variance, low-bias models gives a lower-variance model. Bagging trains trees on bootstrap resamples. Random forests also restrict each split to a random subset of features, so the trees differ more and their errors cancel better. Boosting trains small trees in sequence, each correcting the errors of the previous ones. You lose the single readable rule set and gain accuracy and stability.
Exercise
You fit a regression tree on inputs between 0 and 10, then predict at x = 50. What does it return, and why?
Show answer
It returns the mean target of the leaf that covers the largest x values in training, the same as for any x above the highest split threshold. Each leaf stores a constant, and the tree has no rule that extends a trend beyond the data.
Exercise
Why can a greedy tree fail on XOR data, where the label is 1 when exactly one of two binary features is 1?
Show answer
Splitting on either feature alone leaves both children with a 50/50 class mix, so the impurity decrease is zero. The greedy search sees no useful first split, even though two splits together classify perfectly.