Abstract
Although Shapley Values (SV) are widely used in explainable AI, they can be poorly understood and estimated, implying that their analysis may lead to spurious inferences and explanations. As a starting point, we remind an invariance principle for SV and derive the correct approach for computing the SV of categorical variables that are particularly sensitive to the encoding used. In the case of tree-based models, we introduce two estimators of Shapley Values that exploit the tree structure efficiently and are more accurate than state-of-the-art methods. Simulations and comparisons are performed with state-of-the-art algorithms and show the practical gain of our approach. Finally, we discuss the ability of SV to provide reliable local explanations. We also provide a Python package that compute our estimators at https://github.com/salimamoukou/acv00.
Introduction
Shapley Values (SVs) have emerged as the gold standard for Explainable AI (XAI), providing a mathematically grounded way to attribute feature importance to specific model predictions. However, computing exact SVs is computationally explosive ($O(2^p)$ for $p$ features), necessitating approximations. Current implementations, particularly for tree-based models like Random Forests or XGBoost, often suffer from two major flaws: the incorrect handling of categorical variables and a reliance on independence assumptions that fail when features are correlated.
The Categorical Variable Fallacy
A common practice in machine learning is to one-hot or dummy encode categorical variables. When generating explanations, practitioners often compute the SV for each binary column and sum them to represent the "total" importance of the original category.
As shown in the figure above, this approach is mathematically flawed. Summing the results of individual dummy variables does not equal the contribution of the original single player in the cooperative game. The authors prove that to maintain mathematical invariance, encoded variables must be treated as a single "coalition." On real-world datasets like the Adult Census, using the incorrect "sum" method can completely flip feature rankings, potentially leading to misleading conclusions about model behavior.
Robust Estimators for Tree Models
To address the limitations of existing methods like TreeSHAP, which implicitly assumes feature independence, the authors propose two new approaches:
- Discrete Estimator: This method utilizes quantile discretization of continuous variables to estimate conditional expectations without the need for complex kernel smoothing.
- Leaf-based Estimator: This estimator leverages the actual leaf structure of a trained tree to estimate conditional probabilities. By replacing exact feature conditions with the condition that a feature falls into the same leaf node, it accounts for feature dependencies that TreeSHAP ignores.
To ensure these methods are practical, the authors developed a Multi-Games Algorithm. This algorithm decomposes the massive Shapley game into a sum of smaller games defined on each leaf, reducing computational complexity from exponential in the number of features to exponential only in the depth of the tree.
Experimental Results
The proposed estimators were benchmarked using synthetic datasets with controlled feature correlation ($\rho$) and standard UCI benchmarks.
As illustrated in the results, TreeSHAP's accuracy degrades significantly as feature correlation increases. In contrast, the Leaf-based estimator maintains high accuracy even in highly dependent environments. On synthetic data with $\rho=0.7$, the Leaf estimator achieved a Relative Absolute Error (R-MAE) of 0.90, compared to 3.31 for TreeSHAP. Furthermore, the Leaf estimator demonstrated a 94% True Positive Rate for identifying the top three most important features, outperforming TreeSHAP's 86%.
While TreeSHAP remains faster due to its high optimization (e.g., ~3ms vs. ~1min on the Adult dataset), the Leaf estimator scales effectively with dimensionality, processing 500 features in approximately one minute.
Conclusion
This research highlights critical pitfalls in how Shapley Values are currently applied to categorical and correlated data. By treating encoded variables as coalitions and utilizing the leaf structure of trees, the proposed estimators provide more reliable and accurate explanations.
One significant theoretical finding is that Shapley Values may not be strictly "local"; a feature can receive importance for a specific prediction even if the model's decision path for that observation did not use it. Future work will focus on developing new algorithms that provide a more isolated view of strictly local model behavior.
Summary updated