Plotting Shapley values
Construct Shapley-based importance plots or Shap-based dependence plots.
## S3 method for class 'explain' autoplot( object, type = c("importance", "dependence", "contribution"), feature = NULL, num_features = NULL, X = NULL, color_by = NULL, smooth = FALSE, smooth_color = "red", smooth_linetype = "solid", smooth_size = 1, smooth_alpha = 1, row_num = NULL, ... )
object |
An object of class |
type |
Character string specifying which type of plot to construct.
Current options are |
feature |
Character string specifying which feature to use when
|
num_features |
Integer specifying the number of variables to plot.
Default is |
X |
A matrix-like R object (e.g., a data frame or matrix) containing ONLY the feature columns from the training data. |
color_by |
Character string specifying an optional feature column in
|
smooth |
Logical indicating whether or not to add a smoother to the
scatterplot whenever |
smooth_color |
The color to use for the smoother whenever
|
smooth_linetype |
The type of line to use for the smoother whenever
|
smooth_size |
The size to use for the smoother whenever
|
smooth_alpha |
The transparency to use for the smoother whenever
|
row_num |
Integer specifying a single row/instance in |
... |
Additional optional arguments to be passed on to
|
A "ggplot"
object; see
ggplot2-package
for details.
# # A projection pursuit regression (PPR) example # # Load the sample data; see ?datasets::mtcars for details data(mtcars) # Fit a projection pursuit regression model mtcars.ppr <- ppr(mpg ~ ., data = mtcars, nterms = 1) # Compute approximate Shapley values using 10 Monte Carlo simulations set.seed(101) # for reproducibility shap <- explain(mtcars.ppr, X = subset(mtcars, select = -mpg), nsim = 10, pred_wrapper = predict) shap # Shapley-based plots library(ggplot2) autoplot(shap) # Shapley-based importance plot autoplot(shap, type = "dependence", feature = "wt", X = mtcars) autoplot(shap, type = "contribution", row_num = 1) # explain first row of X
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.