Abstract
Out-Of-Distribution (OOD) generalization is an essential topic in machine learning. However, recent research is only focusing on the corresponding methods for neural networks. This paper introduces a novel and effective solution for OOD generalization of decision tree models, named Invariant Decision Tree (IDT). IDT enforces a penalty term with regard to the unstable/varying behavior of a split across different environments during the growth of the tree. Its ensemble version, the Invariant Random Forest (IRF), is constructed. Our proposed method is motivated by a theoretical result under mild conditions, and validated by numerical tests with both synthetic and real datasets. The superior performance compared to non-OOD tree models implies that considering OOD generalization for tree models is absolutely necessary and should be given more attention.
Introduction
Machine learning models typically assume that training and testing data come from the same distribution. However, in real-world applications, this assumption often fails. Models frequently learn "spurious correlations"—patterns that hold true in a specific training set but do not generalize to new environments. For instance, a financial model might identify a correlation that exists only during a bull market but disappears during a bear market.
Standard decision trees are "greedy" algorithms; they select features that provide the best average performance on training data, regardless of whether that feature's behavior is stable across different contexts. This leads to poor Out-Of-Distribution (OOD) generalization. The Invariant Random Forest (IRF) addresses this by prioritizing features that maintain a stable relationship with the target variable across varying environments.
Methodology
The authors propose the Invariant Decision Tree (IDT) and its ensemble counterpart, the Invariant Random Forest (IRF). The core innovation is a modified splitting criterion that incorporates a penalty term ($\lambda L$) measuring the variance of a split's behavior across different training environments.
- Classification: The model utilizes a mathematical "invariant"—a ratio of label changing rates—that should remain constant across environments for stable features. The penalty increases if this ratio fluctuates.
- Regression: The penalty is based on the variance of the "changing rate" (the difference in label means before and after a split) across all training environments.
- Ensemble (IRF): Unlike traditional Random Forests that use random feature subsets, IRF considers all features but uses the penalty term to naturally filter out unstable, environment-dependent variables.
Experimental Results
The IRF was validated using synthetic data (dimensions $d=2$ to $20$) and real-world datasets including financial indicators, energy consumption, and air quality metrics.
A key finding is that as the penalty weight ($\lambda$) increases, the model successfully shifts its attention from "environmental" (unstable) variables toward "stable" ones. This transition is critical for maintaining performance when the test distribution shifts.
In synthetic tests, IRF's performance advantage over standard Random Forests and XGBoost grew as the dataset dimensionality increased. In real-world regression tasks, such as predicting air quality, IRF reduced Mean Square Error (MSE) by up to 15% compared to standard Random Forests. Interestingly, XGBoost often performed worse than standard Random Forests in OOD scenarios, suggesting that bagging may be inherently more robust to distribution shifts than boosting.
Conclusion
IRF provides a robust, interpretable solution for OOD generalization in tree-based models. While the method currently requires explicit environment labels during training, it demonstrates that prioritizing stability over raw training accuracy leads to significantly better real-world performance. Future work will focus on automatically discovering environments when metadata is unavailable and refining hyperparameter tuning for the penalty weight $\lambda$.
Summary updated