It is pretty easy to compute and plot SHAP interaction values with Python: https://h1ros.github.io/posts/explain-the-interaction-values-by-shap/ or https://towardsdatascience.com/analysing-interactions-with-shap-8c4a2bc11c2a
I would like to do the same in R, preferably by using the packages kernelshap (compute SHAP values ) and shapviz (visualize SHAP). However, I struggle to find the equivalent for computing SHAP interaction values and how to plot them--can anyone please help?
The development version of "shapviz" now contains
devtools::install_github("mayer79/shapviz")
library(shapviz)
library(xgboost)
dtrain <- xgb.DMatrix(data.matrix(iris[, -1]), label = iris[, 1])
fit <- xgb.train(data = dtrain, nrounds = 50)
x2 <- shapviz(fit, X_pred = dtrain, X = iris[, -1], interactions = TRUE)
sv_dependence(x2, "Petal.Length", interactions = TRUE)
sv_dependence(x2, "Petal.Length", color_var = "auto", interactions = TRUE)
You can calculate SHAP values with packages "xgboost" and "treeshap" (and then plot them eg with "ggplot2".)
Example with XGBoost: predict(..., predinteraction=TRUE)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.