#7477·LightGBM

Use QuadratureTreeSHAP for Shapley value computation

Author: ron-wettensteinCreated Sep 29, 2026Updated Sep 30, 2026
Labelsfeature requestefficiency

Summary

The idea is to replace the current TreeSHAP implementation with the Quadrature-TreeSHAP algorithm. The Quadrature TreeSHAP approach is faster and more numerically stable. See paper: https://arxiv.org/abs/2605.04497 and the table below. Since v3.3.0 it has replaced XGBoost's TreeSHAP approach. I worked on the development of this algorithm along with Rory Mitshell and Peng Yu. I will be happy to help migrate it to LightGBM. We can also use this opportunity to support pairwise Shapley interaction values.

Motivation

The approach is faster and more numerically stable than the current implementation, especially for deep trees, which are common in LightGBM.

Description

Quadrature TreeSHAP is the new state-of-the-art algorithm for computing Path Dependent SHAP. Like Linear TreeSHAP, it uses polynomial representation. The paper formulated the weighted banzhaf polynomial on decision trees. Its variable is p: the participating probability of a player. At p=0.5 the polynomial will return the regular Banzhaf values, where each player has a 50% chance to participate. Turns out that the integral of this polynomial in [0,1] provides the Shapley values. The algorithm computes this integral using 8 point Gauss-Legendre.

So basically we traverse the tree, computing this polynomial output on 8 points using interpolation (we never construct the polynomial). Then we compute a weighted average of the results to get the Shapley values. This operation is numerically stable, all is simple arithmetics.

Its complexity is O(nTC) instead of the original TreeSHAP complexity of O(nTD^2) where n is the number of rows we explain, T is the number of trees in the ensemble, D is the tree depth and C<D is the number of Gauss-Legenree points (C=8 in XGBoost). In theory you need C=D/2 to get exact Shapley values. In the paper, we show 8 points are enough to reach the float32 noise floor (~10^-6). To reach the float64 noise floor, 16 points should be enough. To be on the safe side, we can use C=D/2, and get the exact values.

The shapiq package recently implemented the Quadrature-TreeSHAP algorithm in C++. It uses C=D/2 to get the exact values. This package can be used to compute Shapley values on a LightGBM model. I trained a LightGBM model with 100 trees, varying depth and up to 2047 leaves per tree on the Fashion-MNIST dataset. I then compared the running time and accuracy of the shapiq package and the LightGBM package. This experiment can simulate how a LightGBM QuadrateTreeSHAP implementation will behave. QTS time (s) is the runtime of shapiq's QuadratureTreeSHAP implementation. Numerical stability is measured by the maximum efficiency error over 100 explained instances. The efficiency error is the absolute difference between the sum of the Shapley values and the model prediction minus the expected value. The link to the notebook I used is in the references below.

Effective depth QTS time (s) LightGBM time (s) QTS eff. max LightGBM eff. max
10 0.710 2.191 1.066e-14 1.599e-14
20 2.897 17.756 1.243e-14 6.128e-13
30 8.301 37.482 1.421e-14 1.265e-10
40 5.859 57.078 1.865e-14 6.815e-08
50 11.728 76.604 1.243e-14 3.297e-05
60 8.660 101.620 2.132e-14 1.123e-02
70 9.652 121.094 1.421e-14 5.375e+00
80 9.891 137.311 3.286e-14 7.974e+02
90 9.899 146.284 1.776e-14 6.098e+05
100 10.148 151.445 1.865e-14 4.227e+07

As seen in the table, QuadratureTreeSHAP is faster than the current LightGBM TreeSHAP implementation by up to an order of magnitude. It also remains numerically stable at high depths, while LightGBM TreeSHAP becomes unstable as depth increases.

I used max_leaves=2047 so the trees will reach a high depth. A LightGBM model with the default hyperparameters (max_leaves=31, max_depth=None) on Fashion-MNIST reaches depth 17. On this model QTS time is 0.146 seconds, LightGBM time is 0.153 seconds, QTS eff. max is 7.994e-15 and LightGBM eff. max is 2.658e-15.

References

Quadrature-TreeSHAP paper: https://arxiv.org/abs/2605.04497 The notebook that created the numbers for the table above: https://colab.research.google.com/drive/1GEAIPaObb09oGDATqRQ_vmNl6LW0vFK8?usp=sharing XGBoost CPU implementation PR: https://github.com/dmlc/xgboost/pull/12179 XGBoost GPU implementation PR: https://github.com/dmlc/xgboost/pull/12192 Shapiq implementation: https://github.com/mmschlk/shapiq/pull/588 This LightGBM issue might be relevant (SHAP in linear trees): https://github.com/lightgbm-org/LightGBM/issues/4002