Plots a beeswarm plot for each feature pair. Diagonals represent the main effects,
while off-diagonals show interactions (multiplied by two due to symmetry).
The colors on the beeswarm plots represent min-max scaled feature values.
Non-numeric features are transformed to numeric by calling data.matrix()
first.
The features are sorted in decreasing order of usual SHAP importance.
sv_interaction(object, ...)
# Default S3 method
sv_interaction(object, ...)
# S3 method for class 'shapviz'
sv_interaction(
object,
kind = c("beeswarm", "no"),
max_display = 7L,
alpha = 0.3,
bee_width = 0.3,
bee_adjust = 0.5,
viridis_args = getOption("shapviz.viridis_args"),
color_bar_title = "Row feature value",
sort_features = TRUE,
...
)
# S3 method for class 'mshapviz'
sv_interaction(
object,
kind = c("beeswarm", "no"),
max_display = 7L,
alpha = 0.3,
bee_width = 0.3,
bee_adjust = 0.5,
viridis_args = getOption("shapviz.viridis_args"),
color_bar_title = "Row feature value",
sort_features = TRUE,
...
)
An object of class "(m)shapviz" containing element S_inter
.
Arguments passed to ggplot2::geom_point()
. For instance,
passing size = 1
will produce smaller dots.
Set to "no" to return the matrix of average absolute SHAP interactions (or a list of such matrices in case of object of class "mshapviz"). Due to symmetry, off-diagonals are multiplied by two. The default is "beeswarm".
How many features should be plotted?
Set to Inf
to show all features. Has no effect if kind = "no"
.
Transparency of the beeswarm dots. Defaults to 0.3.
Relative width of the beeswarms.
Relative bandwidth adjustment factor used in estimating the density of the beeswarms.
List of viridis color scale arguments. The default points to the
global option shapviz.viridis_args
, which corresponds to
list(begin = 0.25, end = 0.85, option = "inferno")
. These values are passed to
ggplot2::scale_color_viridis_c()
. For example, to switch to standard viridis,
either change the default with options(shapviz.viridis_args = list())
or set
viridis_args = list()
.
Title of color bar of the beeswarm plot. Set to NULL
to hide the color bar altogether.
Should features be sorted or not? The default is TRUE
.
A "ggplot" (or "patchwork") object, or - if kind = "no"
- a named
numeric matrix of average absolute SHAP interactions sorted by the average
absolute SHAP values (or a list of such matrices in case of "mshapviz" object).
sv_interaction(default)
: Default method.
sv_interaction(shapviz)
: SHAP interaction plot for an object of class "shapviz".
sv_interaction(mshapviz)
: SHAP interaction plot for an object of class "mshapviz".
dtrain <- xgboost::xgb.DMatrix(
data.matrix(iris[, -1]), label = iris[, 1], nthread = 1
)
fit <- xgboost::xgb.train(data = dtrain, nrounds = 10, nthread = 1)
x <- shapviz(fit, X_pred = dtrain, X = iris, interactions = TRUE)
sv_interaction(x, kind = "no")
#> Petal.Length Sepal.Width Petal.Width Species
#> Petal.Length 0.61216324 0.07647426 0.0439800713 0.0241938784
#> Sepal.Width 0.07647427 0.07895533 0.0381466559 0.0103276318
#> Petal.Width 0.04398007 0.03814666 0.0428673263 0.0006772984
#> Species 0.02419387 0.01032763 0.0006773004 0.0190167296
sv_interaction(x, max_display = 2, size = 3)