Learn R Programming

treeshap (version 0.3.1)

plot_feature_dependence: SHAP value based Feature Dependence plot

Description

Depending on the value of a variable: how does it contribute into the prediction?

Usage

plot_feature_dependence(
  treeshap,
  variable,
  title = "Feature Dependence",
  subtitle = NULL
)

Value

a ggplot2 object

Arguments

treeshap

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

variable

name or index of variable for which feature dependence will be plotted.

title

the plot's title, by default 'Feature Dependence'.

subtitle

the plot's subtitle. By default no subtitle.

See Also

treeshap for calculation of SHAP values

plot_contribution, plot_feature_importance, plot_interaction

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 = FALSE)
unified_model <- xgboost.unify(xgb_model, as.matrix(data))
x <- head(data, 100)
shaps <- treeshap(unified_model, x)
plot_feature_dependence(shaps, variable = "overall")
# }

Run the code above in your browser using DataLab