Convert your GBM model into a standardized representation.
The returned representation is easy to be interpreted by the user and ready to be used as an argument in treeshap() function.
gbm.unify(gbm_model, data)a unified model representation - a model_unified.object object
# \donttest{
if (requireNamespace("gbm", quietly = TRUE)) {
library(gbm)
data <- fifa20$data[colnames(fifa20$data) != 'work_rate']
data['value_eur'] <- fifa20$target
gbm_model <- gbm::gbm(
formula = value_eur ~ .,
data = data,
distribution = "gaussian",
n.trees = 20,
interaction.depth = 4,
n.cores = 1)
unified_model <- gbm.unify(gbm_model, data)
shaps <- treeshap(unified_model, data[1:2,])
plot_contribution(shaps, obs = 1)
}# }
#> Loaded gbm 2.2.3
#> This version of gbm is no longer under development. Consider transitioning to gbm3, https://github.com/gbm-developers/gbm3
#>
|0%----|------|20%---|------|40%---|------|60%---|------|80%---|------|100%
#> =---------------------------------------------------------------------- (0%)
====================================----------------------------------- (50%)
======================================================================= (100%)
#> `height` was translated to `width`.