Machine Learning · Tree Ensembles

Why Piecewise-Constant Tree Ensembles Cannot Extrapolate

Beyond the largest value seen in training, every threshold test returns the same answer, so the prediction freezes. The consequence and the partial remedies follow from the shape of the fitted function.

A tree prediction is produced by walking a finite sequence of threshold comparisons and returning the value stored at the leaf reached. Nothing in that walk can produce a quantity that grows with the input. Once an input coordinate passes the largest threshold the tree contains for that coordinate, every remaining test on it returns the same answer, the path is fixed, and the output is a constant.

This is not a defect of a particular implementation or a consequence of limited depth. It is what the function class contains. Every property that follows, from the flat forecasts of boosted models on a time index to the zero gradient almost everywhere, is a restatement of the same fact.

The path stops changing

A fitted tree is a partition of the input space into axis-aligned cells, with one constant value per cell. Depth $d$ produces at most $2^d$ leaves, so a tree of depth 6 has at most 64 distinct outputs and at most 6 thresholds on any path. For a regression forest of 500 such trees the number of distinct sums is large but finite, and each coordinate is cut by only the thresholds that appear on the paths actually reachable.

Consider a single feature $x_j$ with the other coordinates fixed. The prediction as a function of $x_j$ changes only when $x_j$ crosses a threshold stored in some tree along the path for those other coordinates. Between thresholds the output is constant, and beyond the largest such threshold it is constant forever. The number of distinct values the model can take along that line is one more than the number of distinct thresholds it uses on that line, which is bounded by the total number of nodes in the ensemble.

That bound is the whole argument. There is no mechanism by which a leaf value could depend on how far past the threshold an input lies, because the leaf value is a fitted constant and the comparison has already saturated.

A boundary case, computed

Take a stump fitted to a training set where the predictor ranges over $[0, 100]$ and the split is at $x \le 60$ with left value 12.0 and right value 47.0. At $x = 100$ the prediction is 47.0. At $x = 10^6$ the prediction is also 47.0, and so is the prediction at any larger value that can be represented.

def predict(node, x):
    while node.left is not None:
        node = node.left if x[node.feature] <= node.threshold else node.right
    return node.value

# Both calls return the same leaf value: no threshold exceeds 100.
assert predict(tree, {"x": 100.0}) == predict(tree, {"x": 1e9})

Adding trees does not change this. A boosted ensemble fits successive trees to the residuals of the current sum, and inside the training range many small steps can approximate a rising line closely enough that the sum looks linear. Outside the range, each additional tree contributes its own constant for that region, and the sum is still a constant. The approximation error of a staircase to a line grows with the distance from the last step, but the staircase is what the model contains, and the individual step heights are fitted to residuals that exist only where data exists.

The same reasoning applies to the training range boundary in every coordinate. A prediction for a combination of features that lies outside the convex hull of the training data is an extrapolation along at least one axis, and along that axis the model contributes no trend. Two points outside the hull may receive identical predictions even though the fitted surface inside the hull is steeply sloped near the boundary.

Why more rounds cannot repair it

Gradient boosting’s residual fitting is sometimes described as if it continued the trend. It does not. The gradient at a point outside the training support is zero for squared error only in the trivial sense that no such point exists in the training set; the ensemble is fitted to residuals at training coordinates, and each tree it adds is constant beyond the largest training value.

A concrete way to see the limit: the final prediction is $\sum_m \nu, h_m(x)$. For $x_j$ beyond all thresholds in all trees, each $h_m(x)$ equals the value of its rightmost leaf along that path, a constant determined at fit time. The sum of constants is a constant, independent of $x_j$. Making the learning rate smaller, the rounds more numerous, or the trees deeper changes which constants are stored and does not introduce a dependence on $x_j$.

Histogram binning makes the flat region start earlier. After binning, an out-of-range value maps to the last bin, so the model cannot distinguish $x_j = 101$ from $x_j = 10^6$ even in principle; the distinction was destroyed before any tree was fitted. This is one of the costs noted in histogram split finding, and it is benign inside the training range and fatal outside it.

Partial remedies and what each one actually buys

Model the trend outside the trees. Decompose the target into a component with known functional form and a residual, fit the trees to the residual, and add the components at prediction time. A linear or seasonal term continues past the end of the data because it is not a tree. The residual model is then only asked to interpolate, which trees do well. The catch is that the decomposition is an assumption: if the trend changes regime, the extrapolating component is confidently wrong where the tree would at least have stayed flat.

Put a linear model in the leaves. A model tree stores a small regression at each leaf rather than a constant, fitted to the rows that reach it. Inside the leaf’s cell the prediction now has a slope, so the fitted surface is continuous piecewise linear rather than piecewise constant, and it can continue a trend slightly beyond the cell. It still cannot extrapolate safely far outside the training range, because the leaf’s coefficients were fitted on a local window and are unconstrained elsewhere. The benefit is a better local fit with fewer leaves, which is why model trees were proposed as a lower-variance alternative to deep constant trees.

Transform the target. A log transform, a first difference, or a detrended residual can make the target flat where it was rising, and a flat target is exactly what trees can represent. This works when the transformation encodes the structure that matters, which is why differencing is standard for non-stationary series. It does not create extrapolation in the original scale: a constant in log space is a constant in the original space after the inverse transform, and a constant first difference is a linear function of time only if the differenced prediction is applied cumulatively, which makes the recursion, not the tree, responsible for the trend.

Smooth the output. Averaging leaf values over a neighbourhood, or replacing hard threshold tests with soft ones, produces a continuous surface with a nonzero gradient outside the data. The gradient comes from the smoothing kernel, not from the fitted structure, and it typically decays, so the model returns toward a global mean rather than following the trend. That is a reasonable default behaviour and a poor forecasting method.

Use a different model class for the extrapolating part. A linear model, a Gaussian process with a trend mean, or a physical model can carry the trend; the ensemble handles the nonlinear residual. The composition has to be explicit, because a stacked model whose second stage is also a tree inherits the same limitation.

Consequences for search and for interpretation

Because the fitted function is constant between thresholds, its derivative with respect to any input is zero almost everywhere and undefined at the threshold set. Optimizing an input to minimize or maximize the prediction therefore has no gradient to follow: a gradient-based search over feature values sees a zero vector and stalls, and a search that perturbs coordinates discovers that most perturbations leave the output untouched.

This is the mechanism behind a class of failures in model-based optimization and in feature-attribution methods that rely on local gradients. It is also why tree ensembles are resistant to small adversarial perturbations compared with smooth models and vulnerable to perturbations that cross a threshold: the sensitivity of the output to a change in one feature is either zero or a full jump, with nothing in between.

Partial dependence plots inherit the same shape. A one-dimensional partial dependence is an average of the model over the training distribution of the other features, and beyond the range of the plotted feature it flattens, because every tree has stopped discriminating. The flat tail is often read as evidence that the effect saturates; it is evidence only that the data ended.

For interpolation the same structure is an advantage. A piecewise-constant fit cannot oscillate between training points the way a high-degree polynomial can, and it is invariant to monotone transformations of individual features apart from the placement of thresholds. The failure is specific: the model is a lookup table over a partition learned from data, and a lookup table has nothing to say about rows it has never seen. Recognizing which regime a prediction falls into is more useful than trying to make the function class do something it cannot. The split search that produces the partition is described in the CART threshold scan, and the ensemble variants that average or accumulate it are the subject of the rest of this cluster.

References

  1. Classification and Regression Trees — Breiman, Friedman, Olshen & Stone, Wadsworth 1984
  2. Learning with Continuous Classes — Quinlan, Proceedings of the 5th Australian Joint Conference on Artificial Intelligence, 1992
  3. The Elements of Statistical Learning, Chapter 9: Additive Models, Trees, and Related Methods — Hastie, Tibshirani & Friedman, Springer