Abstract
Tree ensembles such as Random Forests and XGBoost are widely used due to their high predictive performance, yet their non-differentiable nature poses significant challenges for generating counterfactual explanations. We present FOCUS (Flexible Optimizable Counterfactual Explanations for Tree Ensembles), a framework that employs a differentiable probabilistic approximation of tree ensembles to enable gradient-based optimization. Our method consistently finds minimal perturbations required to alter model predictions, achieving a 100% success rate across multiple benchmark datasets while outperforming existing heuristic and optimization-based baselines.
Introduction
In the field of eXplainable AI (XAI), counterfactual explanations are considered the gold standard for providing actionable feedback. For instance, if a loan application is denied, a counterfactual explanation might state: "Had your annual income been $5,000 higher, your loan would have been approved." This provides the user with a clear path toward a desired outcome.
The most efficient way to generate these explanations is through gradient-based optimization—essentially "walking" toward the decision boundary. However, this requires the underlying model to be differentiable. This requirement excludes tree ensembles (Random Forests, Gradient Boosted Trees), which are among the most popular models in industry but are non-differentiable due to their discrete, "hard" step-function splits. Existing methods for trees typically rely on heuristic searches through leaf nodes, which are often slow, fail to find explanations for every instance, or produce suboptimal results that require larger changes than necessary.
Methodology: The FOCUS Framework
FOCUS bridges the gap between non-differentiable tree models and gradient-based optimization through a three-step approach that creates a differentiable "proxy" of the ensemble.
1. Probabilistic Approximation
The core innovation involves replacing the discrete decision thresholds of a tree (e.g., $x > 0.5$) with a continuous sigmoid function. As the scaling parameter ($\sigma$) increases, this smooth curve mimics the original hard split more closely, providing a gradient "map" that points toward the decision boundary.
2. Softmax Aggregation
For ensembles, FOCUS replaces the standard majority vote or maximum operator with a softmax function. This ensures that the entire ensemble's output is differentiable with respect to the input features.
3. Optimization Framework
With a differentiable proxy model, FOCUS defines a loss function that balances two competing goals:
- Prediction Loss: A hinge-loss that pushes the input toward a different classification.
- Distance Loss: A penalty (such as Euclidean or Manhattan distance) that keeps the counterfactual as close to the original input as possible.
By optimizing this loss using the Adam optimizer, FOCUS finds a "minimal perturbation" that flips the prediction of the original, non-differentiable model.
Experimental Evaluation
The authors evaluated FOCUS on four binary classification datasets: Wine Quality, HELOC (FICO), COMPAS (criminal recidivism), and Shopping (online purchase prediction). These were tested across three model types: Decision Trees (DT), Random Forests (RF), and AdaBoost (AB).
Key Results and Discussion
Reliability and Success Rate
A major challenge with existing tree-specific counterfactual methods, such as Feature Tweaking, is their tendency to fail when searching complex ensembles. In contrast, FOCUS achieved a 100% success rate in finding valid counterfactuals across all test cases. This reliability makes it a robust choice for real-world applications where consistent feedback is required.
Minimality and Scalability
Because FOCUS uses gradients rather than jumping between leaf nodes, it can find points much closer to the decision boundary. In 20 out of 36 experimental settings, FOCUS produced counterfactuals significantly closer to the original data than the Feature Tweaking baseline. Furthermore, FOCUS significantly outperformed DACE (a state-of-the-art optimization baseline), which struggled with larger models due to the complexity of its mixed-integer linear programming approach.
Conclusion and Future Work
FOCUS demonstrates that differentiability can be used as a proxy to navigate non-differentiable models. By providing a reliable and efficient optimization framework, it allows for the generation of high-quality counterfactuals for the most common models in tabular data science. Future research will focus on incorporating "actionability" constraints—ensuring that suggested changes are physically possible (e.g., not decreasing a user's age)—and conducting user studies to align mathematical minimality with human preferences.
Summary updated