shap.prep.interaction: Prepare the interaction SHAP values from predict.xgb.Booster

Description Usage Arguments Value Examples

View source: R/SHAP_funcs.R

Description

shap.prep.interaction just runs shap_int <- predict(xgb_mod, (X_train), predinteraction = TRUE), thus it may not be necessary. Read more about the xgboost predict function at xgboost::predict.xgb.Booster. Note that this functionality is unavailable for LightGBM models.

Usage

1
shap.prep.interaction(xgb_model, X_train)

Arguments

xgb_model

a xgboost model object

X_train

the dataset of predictors used for the xgboost model

Value

a 3-dimention array: #obs x #features x #features

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# To get the interaction SHAP dataset for plotting:
# fit the xgboost model
mod1 = xgboost::xgboost(
  data = as.matrix(iris[,-5]), label = iris$Species,
  gamma = 0, eta = 1, lambda = 0,nrounds = 1, verbose = FALSE)
# Use either:
data_int <- shap.prep.interaction(xgb_mod = mod1,
                                  X_train = as.matrix(iris[,-5]))
# or:
shap_int <- predict(mod1, as.matrix(iris[,-5]),
                    predinteraction = TRUE)

# **SHAP interaction effect plot **
shap.plot.dependence(data_long = shap_long_iris,
                           data_int = shap_int_iris,
                           x="Petal.Length",
                           y = "Petal.Width",
                           color_feature = "Petal.Width")

Example output

`geom_smooth()` using formula 'y ~ x'

SHAPforxgboost documentation built on March 28, 2021, 9:06 a.m.