Learn R Programming

treeshap (version 0.3.1)

xgboost.unify: Unify XGBoost model

Description

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

Usage

xgboost.unify(xgb_model, data, recalculate = FALSE)

Value

a unified model representation - a model_unified.object object

Arguments

xgb_model

A XGBoost model - object of class xgb.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.

See Also

lightgbm.unify for LightGBM models

gbm.unify for GBM models

ranger.unify for ranger models

randomForest.unify for randomForest models

Examples

Run this code
# \donttest{
library(xgboost)
data <- fifa20$data[colnames(fifa20$data) != 'work_rate']
target <- fifa20$target
param <- list(objective = "reg:squarederror", max_depth = 3)
xgb_model <- xgboost::xgboost(as.matrix(data), params = param, label = target,
                              nrounds = 20, verbose = 0)
unified_model <- xgboost.unify(xgb_model, as.matrix(data))
shaps <- treeshap(unified_model, data[1:2,])
plot_contribution(shaps, obs = 1)
# }

Run the code above in your browser using DataLab