Convert your GPBoost 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.

gpboost.unify(gpb_model, data, recalculate = FALSE)

Arguments

gpb_model

A gpboost model - object of class gpb.Booster

data

Reference dataset. A data.frame or matrix with the same columns as in the training set of the model. Usually dataset used to train model.

recalculate

logical indicating if covers should be recalculated according to the dataset given in data. Keep it FALSE if training data are used.

Value

a unified model representation - a model_unified.object object

Examples

# \donttest{
library(gpboost)
#> Loading required package: R6
param_gpb <- list(objective = "regression", max_depth = 2,
                   force_row_wise = TRUE, num_iterations = 20)
data_fifa <- fifa20$data[!colnames(fifa20$data) %in%
             c('work_rate', 'value_eur', 'gk_diving', 'gk_handling',
             'gk_kicking', 'gk_reflexes', 'gk_speed', 'gk_positioning')]
data <- na.omit(cbind(data_fifa, fifa20$target))
sparse_data <- as.matrix(data[,-ncol(data)])
x <- gpboost::gpb.Dataset(sparse_data, label = as.matrix(data[,ncol(data)]))
gpb_data <- gpboost::gpb.Dataset.construct(x)
gpb_model <- gpboost::gpboost(data = gpb_data, params = param_gpb,
                                verbose = -1, num_threads = 0)
unified_model <- gpboost.unify(gpb_model, sparse_data)
shaps <- treeshap(unified_model, data[1:2, ])
#> 
|0%----|------|20%---|------|40%---|------|60%---|------|80%---|------|100%
#> =---------------------------------------------------------------------- (0%)

====================================----------------------------------- (50%)

======================================================================= (100%)

plot_contribution(shaps, obs = 1)
#> `height` was translated to `width`.

# }