Why are tree-based models generally invariant to monotonic feature transformations?
Quick Overview
Asks why decision trees, random forests and gradient-boosted models are largely unaffected by monotonic feature transformations such as scaling or a log. Tests understanding of threshold splits, how impurity is computed, and the edge cases where the invariance stops holding.
Why are tree-based models generally invariant to monotonic feature transformations?
Role: Machine Learning Engineer
Category: Machine Learning
Difficulty: medium
Interview Round: Other
Why are tree-based models generally invariant to monotonic feature transformations?
Here a tree-based model means a single decision tree, a random forest or a gradient-boosted ensemble, and a monotonic transformation is something like scaling, a log, a square root or a rank transform applied to one input feature.
```hint What a split looks at
Write down the rule a single split applies to a row, and ask which property of the feature values decides which rows go left and which go right.
```
### What a Strong Answer Covers
- How a threshold split partitions the rows and what the impurity or loss reduction is computed from
- Why a strictly increasing transform leaves the candidate partitions, the gains and the fitted tree unchanged, and what a strictly decreasing transform does
- The practical consequence for feature preprocessing, compared with models that depend on magnitudes such as linear models and kNN
- The cases where the invariance breaks: threshold placement for unseen values, histogram binning, non-strict or non-monotonic transforms, and transforming the target
### Follow-up Questions
- Two trees trained on `x` and on `log(x)` give different predictions for the same test row. How can that happen?
- You log-transform a feature for a gradient-boosted model that bins features into equal-width histograms. What can change, and why?
- Does the same invariance hold for the target in a regression tree? What changes if you train on `log(y)`?
- How would you preprocess a heavy-tailed feature differently for a gradient-boosted model and for a logistic regression?
Overview: Asks why decision trees, random forests and gradient-boosted models are largely unaffected by monotonic feature transformations such as scaling or a log. Tests understanding of threshold splits, how impurity is computed, and the edge cases where the invariance stops holding.
Why are tree-based models generally invariant to monotonic feature transformations?
Here a tree-based model means a single decision tree, a random forest or a gradient-boosted ensemble, and a monotonic transformation is something like scaling, a log, a square root or a rank transform applied to one input feature.
What a Strong Answer Covers Guidance
How a threshold split partitions the rows and what the impurity or loss reduction is computed from
Why a strictly increasing transform leaves the candidate partitions, the gains and the fitted tree unchanged, and what a strictly decreasing transform does
The practical consequence for feature preprocessing, compared with models that depend on magnitudes such as linear models and kNN
The cases where the invariance breaks: threshold placement for unseen values, histogram binning, non-strict or non-monotonic transforms, and transforming the target
Follow-up Questions Guidance
Two trees trained on
x
and on
log(x)
give different predictions for the same test row. How can that happen?
You log-transform a feature for a gradient-boosted model that bins features into equal-width histograms. What can change, and why?
Does the same invariance hold for the target in a regression tree? What changes if you train on
log(y)
?
How would you preprocess a heavy-tailed feature differently for a gradient-boosted model and for a logistic regression?