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 |
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 |
min_max |
a range of OX axis. By default |
digits |
number of decimal places ( |
explain_deviation |
if |
title |
the plot's title, by default |
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))