plot_contribution {treeshap}R Documentation

SHAP value based Break-Down plot

Description

This function plots contributions of features into the prediction for a single observation.

Usage

plot_contribution(
  treeshap,
  obs = 1,
  max_vars = 5,
  min_max = NA,
  digits = 3,
  explain_deviation = FALSE,
  title = "SHAP Break-Down",
  subtitle = ""
)

Arguments

treeshap

A treeshap object produced with the treeshap function. treeshap.object.

obs

A numeric indicating which observation should be plotted. Be default it's first observation.

max_vars

maximum number of variables that shall be presented. Variables with the highest importance will be presented. Remaining variables will be summed into one additional contribution. By default 5.

min_max

a range of OX axis. By default NA, therefore it will be extracted from the contributions of x. But it can be set to some constants, useful if these plots are to be used for comparisons.

digits

number of decimal places (round) to be used.

explain_deviation

if TRUE then instead of explaining prediction and plotting intercept bar, only deviation from mean prediction of the reference dataset will be explained. By default FALSE.

title

the plot's title, by default 'SHAP Break-Down'.

subtitle

the plot's subtitle. By default no subtitle.

Value

a ggplot2 object

See Also

treeshap for calculation of SHAP values

plot_feature_importance, plot_feature_dependence, plot_interaction

Examples


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 = FALSE)
unified_model <- xgboost.unify(xgb_model, as.matrix(data))
x <- head(data, 1)
shap <- treeshap(unified_model, x)
plot_contribution(shap, 1,  min_max = c(0, 120000000))


[Package treeshap version 0.3.1 Index]