Learn R Programming

SHAPforxgboost (version 0.0.2)

shap.prep.stack.data: Prepare data for SHAP force plot (stack plot)

Description

Make force plot for top_n features, option to randomly plot certain portion of the data in case the dataset is large.

Usage

shap.prep.stack.data(shap_contrib, top_n = NULL, data_percent = 1,
  cluster_method = "ward.D", n_groups = 10L)

Arguments

shap_contrib

shap_contrib is the SHAP value data returned from predict.xgb.booster

top_n

integer, optional to show only top_n features, combine the rest

data_percent

what percent of data to plot (to speed up), in the range of (0,1]

cluster_method

default to ward.D

n_groups

a integer, how many groups to plot in shap.plot.force_plot_bygroup

Value

a dataset for stack plot

Examples

Run this code
# NOT RUN {
# **SHAP force plot**
plot_data <- shap.prep.stack.data(shap_contrib = shap_values_iris,
                                  n_groups = 4)
shap.plot.force_plot(plot_data)
shap.plot.force_plot(plot_data,  zoom_in_group = 2)

# plot all the clusters:
shap.plot.force_plot_bygroup(plot_data)
# }

Run the code above in your browser using DataLab