TL;DR
Linear TreeShap is a new, mathematically grounded algorithm that computes exact Shapley values for tree-based models in linear time relative to tree depth. By reframing the explanation problem as polynomial arithmetic, it achieves significant speedups over the industry-standard TreeShap without sacrificing accuracy or increasing memory usage.
What Problem Does This Paper Address?
Tree-based models like Random Forests and Gradient Boosted Trees (XGBoost, LightGBM) are staples of modern machine learning due to their high accuracy. However, as these models grow deeper and more complex, they become opaque "black boxes." To trust and verify these models, practitioners rely on Shapley values—a concept from game theory that fairly distributes the "credit" for a prediction across all input features.
The current gold standard for this computation is TreeShap. While TreeShap was a massive improvement over general-purpose methods, its computational complexity is $O(D^2)$ (where $D$ is the depth of the tree). For the deep trees often used in industry, this quadratic scaling becomes a major bottleneck. Previous attempts to speed this up, like FastTreeShap or GPUTreeShap, were largely empirical or hardware-dependent. This paper seeks a mathematically rigorous way to reach linear complexity ($O(D)$).
Methods
The authors introduce Linear TreeShap, which moves away from traditional tree traversal logic and toward polynomial arithmetic.
- Linearization: They first show that a decision tree can be decomposed into a set of "decision rules" (paths from root to leaf). The Shapley value of the tree is simply the sum of the Shapley values of these individual rules.
- Summary Polynomials: They represent the contribution of features along a path as a "summary polynomial." This allows them to use the properties of polynomials to simplify the complex combinatorial math required for Shapley values.
- The Interpolation Trick: Standard polynomial multiplication and division are still somewhat slow ($O(D \log D)$). To get to true linear time, the authors use multipoint interpolation. Instead of calculating polynomial coefficients directly, they evaluate the polynomials at a set of predefined points (specifically Chebyshev points for numerical stability). In this "interpolation form," addition, multiplication, and division become simple $O(D)$ operations.
- Telescoping Sums: By applying a telescoping sum approach across the edges of the tree, they can share intermediate results between different paths, avoiding redundant calculations.
Datasets
The authors evaluated their algorithm using two standard benchmarks to test across both classification and regression tasks with varying feature counts:
- Adult Dataset: A classification task involving 48,842 instances and 64 attributes, used to predict income levels.
- Conductor Dataset: A regression task with 21,263 instances and 81 attributes, used to predict the critical temperature of superconductors.
Key Insights and Ideas
- Shapley Values as Polynomials: The most elegant "aha moment" is realizing that the weighted sums used in Shapley value calculations are mathematically equivalent to operations on specific types of polynomials.
- Complexity Breakthrough: By shifting the problem into the frequency/interpolation domain (similar to how a Fast Fourier Transform speeds up signal processing), they bypass the quadratic bottleneck of previous methods.
- No Compromise: Unlike many "fast" versions of algorithms, Linear TreeShap is exact. It doesn't use approximations or sampling; it provides the same mathematical result as the original TreeShap, just much faster.
- Memory Efficiency: The algorithm maintains a space complexity of $O(D^2 + N)$, ensuring it can run on standard hardware without the massive memory overhead seen in some caching-heavy alternatives.
Key Results
The experimental results show a clear victory for Linear TreeShap:
- Scaling with Depth: As tree depth increases from 2 to 18, the speedup of Linear TreeShap over the original TreeShap grows significantly.
- Superiority over FastTreeShap: While FastTreeShap v2 is faster than the original, it suffers from heavy memory usage and eventually "falls back" to slower versions at high depths. Linear TreeShap remained the fastest across all tested depths.
- Dataset Sensitivity: The speedup was particularly pronounced on the "Conductor" dataset. Because this dataset has more unique features per decision rule, the polynomial approach had more opportunities to optimize the calculation compared to traditional methods.
Limitations and Future Work
While the paper presents a major algorithmic leap, there are a few areas for further exploration:
- Single-Core Focus: The current benchmarks were performed on a single core to ensure a fair algorithmic comparison. While the method is theoretically parallelizable, its performance in a distributed or GPU-accelerated environment isn't extensively explored here.
- Feature Assumptions: For simplicity, the authors assumed every feature is used in the tree ($N = O(L)$). While this is common in deep trees, the performance might vary in extremely sparse trees where many features are never used for splitting.
- Implementation Complexity: Implementing polynomial interpolation and Chebyshev point evaluation is more complex than the standard recursive tree traversal, which might present a higher barrier for developers looking to integrate this into new ML libraries.
Summary updated