arXiv:2608.24104stat.MLAug 2026

Manuscript Offprint

arXiv:2608.24104

qshap: Fast Shapley Decomposition of R2R^2 for Gradient-Boosted Trees

Zhongli Jiang, Min Zhang, Dabao Zhang

Abstract

Numerous methods have been developed to quantify feature attributions in individual predictions for tree ensembles. However, many applications require global measures of feature contributions to overall model performance. Although local attribution scores can be aggregated to characterize feature importance, such summaries do not directly decompose measures of predictive performance, such as R2R^{2}. This article introduces qshap, available in both R and Python, which provides Shapley decomposition of R2R^{2} values for gradient-boosted decision trees (GBDTs) to quantify feature-specific contributions to model performance. By decomposing the quadratic loss of individual observations, qshap provides flexible tools to explore the importance of individual features and observations. qshap currently supports widely used GBDT implementations, including xgboost, lightgbm, and catboost, through a unified tree representation and efficient C++ backends. Its modular design can accommodate other GBDT implementations built from binary decision trees. In addition, we introduce a specialized backend for oblivious trees that exploits their symmetric structure to substantially accelerate computation.

Keywords: Shapley values, feature-specific R2R^{2}, gradient-boosted decision trees, explainable artificial intelligence, interpretable machine learning.

1. Introduction

Gradient-boosted decision trees (GBDTs) (Friedman 2001), including XGBoost (Chen and Guestrin 2016), LightGBM (Ke, Meng, Finley, Wang, Chen, Ma, Ye, and Liu 2017), and CatBoost (Prokhorenkova, Gusev, Vorobev, Dorogush, and Gulin 2018), are widely used for tabular data because of their predictive performance and scalability. However, interpreting the contributions of individual features remains challenging, particularly as tree depth and ensemble size increase.

Several notions of feature importance are available for fitted tree ensembles, but they answer different questions. Built-in summaries such as split counts and gain importance describe how variables are used by the fitted trees, whereas permutation importance measures the deterioration of a chosen performance criterion after perturbing a variable (Breiman 2001; Fisher, Rudin, and Dominici 2019). To address these limitations, Shapley additive explanations (SHAP; Lundberg and Lee 2017) leverage Shapley values (Shapley 1953) to provide robust feature attributions. Its specialized implementation TreeSHAP (Lundberg, Erion, Chen, DeGrave, Prutkin, Nair, Katz, Himmelfarb, Bansal, and Lee 2020) further introduces a fast and exact polynomial-time algorithm for tree ensembles. The Python package shap qshap: Fast Shapley Decomposition of R2R^{2} for Gradient-Boosted Trees

provides a widely used implementation of SHAP and TreeSHAP. Related software includes the R package treeshap, which provides a unified TreeSHAP interface for several tree ensemble implementations (Mayer, Komisarczyk, Kozminski, Maksymiuk, and Biecek 2026), and the packages shapr and shaprpy, which emphasize conditional coalition values that account for dependency among the input variables (Jullum, Olsen, Lachmann, and Redelmeier 2025). Nonetheless, these methods are designed to explain individual predictions, whereas many applications require a global measure of feature contribution, especially in the fields of biomedical science and finance. Although local SHAP values are often aggregated over observations, for example, by aggregating absolute values (Lundberg et al. 2020), they typically measure average attribution across local quantities, rather than an exact decomposition of model-level goodness of fit.

To characterize global model behavior, several methods apply the Shapley value allocation to measures of predictive performance. In linear regression, Lipovetsky and Conklin (2001) decompose the model R2R^{2} and quantify the relative importance of predictors in the presence of multicollinearity. A closely related formulation is the LMG measure implemented in the R package relaimpo, which averages the incremental R2R^{2} attributed to each predictor over all possible predictor orderings (Grömping 2006). Although these methods provide fair allocations of explained variance, the evaluation generally requires considering permutations that grow exponentially with the feature dimensions, and relaimpo is only available for linear models.

Beyond linear regression, sage-importance implements the SAGE algorithm, which utilizes Shapley allocation based on expected loss reduction and estimates Shapley value feature importance by Monte Carlo sampling over feature subset permutations (Covert, Lundberg, and Lee 2020). Similarly, the Python package vimpy and the R package vimp implement SPVIM, a resampling-based framework for estimating Shapley global variable importance that also supports statistical inference (Williamson and Feng 2020). Shapley effects provide a closely related population-level, variance-based formulation (Song, Nelson, and Staum 2016; Owen and Prieur 2017). While these methods provide general, model-agnostic measures of global feature importance, their computation may require feature-subset sampling, nuisance function estimation, cross-fitting, or repeated model fitting. Their computational cost can therefore become substantial, particularly in high-dimensional settings. The SHAFF method proposed by Bénard, Biau, Da Veiga, and Scornet (2022) uses random forests to guide feature-subset sampling and estimate the explained-variance quantities required for Shapley effects. However, SHAFF relies on sampling and is specifically designed for random forests, and thus does not directly provide an R2R^{2} decomposition for boosted tree ensembles.

In this article, we present a deterministic framework, Q-SHAP (Jiang, Zhang, and Zhang 2025), for computing feature-specific Shapley values of explained variance (i.e., R2R^2) for fitted GBDT models. By exploiting the internal tree structure, Q-SHAP enables fast and exact decomposition of R2R^2 in polynomial time without any sampling or model refitting. In addition, we introduce a specialized algorithm for oblivious trees, in complexity O(nD+min⁡(n,L)LD)O(nD + \min(n, L)LD) for nn samples, where LL is the maximum number of leaves and DD denotes the maximum depth, matching the asymptotic complexity of Linear TreeSHAP (Bifet, Read, Xu et al. 2022). We further introduce the qshap software, implemented in both R and Python, with an efficient backend in C++, supporting large-scale feature attribution with parallel computation, and providing rich visualization tools through a simple, user-friendly interface.

The rest of the paper is organized as follows. Section 2 introduces the theoretical background of Shapley value and details of the Q-SHAP methods. Section 3 describes the design and usage of the R package. Section 4 discusses the Python version of our package. We further discuss the internals and extensibility in Section 5, and we conclude the paper in Section 6.

References (30)