| gg_shap | R Documentation |
gg_shap computes SHAP values for a
rfsrc or
randomForest regression or classification forest
by wrapping kernelshap, and reshapes them into a
tidy data set with one row per (observation, variable).
gg_shap(object, newdata, bg_n = 50, which.class = 1, ...)
object |
A |
newdata |
Optional |
bg_n |
Size of the background/reference sample drawn from the
training predictors and passed to |
which.class |
For classification forests, the class (integer column index into the predicted-probability matrix) whose predicted probability is explained. Defaults to 1. |
... |
Passed through to |
A gg_shap object: a data.frame with columns
id (observation index), vars (variable name, an ordered
factor ranked by mean absolute SHAP), shap (the signed SHAP
contribution), value (numeric feature value, NA for
categorical features), and value_label (feature value as
character). The background-sample mean prediction is stored in the
"baseline" attribute.
kernelshap
if (requireNamespace("kernelshap", quietly = TRUE)) {
rf <- randomForestSRC::rfsrc(Ozone ~ ., data = na.omit(airquality),
ntree = 50)
gg_dta <- gg_shap(rf, bg_n = 20)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.