I have used the caret R package to train a neural network, and a random forest. Can I find the SHAP values for feature importance in any way?
Slightly modified from kernelshap's README: https://github.com/ModelOriented/kernelshap
library(caret)
library(kernelshap)
library(shapviz)
fit <- train(
Sepal.Length ~ . + Species * Sepal.Width,
data = iris,
method = "lm",
tuneGrid = data.frame(intercept = TRUE),
trControl = trainControl(method = "none")
)
xvars <- colnames(iris[-1])
s <- kernelshap(fit, iris, predict, bg_X = iris, feature_names = xvars)
sv <- shapviz(s)
sv_importance(sv)
sv_dependence(sv, xvars)
bg_X
by a subsample of about 200--500 rows.