Plot how a feature's SHAP value is assembled from components
Source:R/plot_shap_decomposition.R
plot_shap_decomposition.RdFor one observation, shows the components involving each selected feature,
starting at the intercept E[f]. Interaction terms are split evenly among
their features, so each feature's bars sum to its SHAP value, shown in the
bottom row. To see the whole prediction instead, use plot_waterfall() or
plot_force().
Usage
plot_shap_decomposition(
object,
id,
threshold = NULL,
max_interaction = NULL,
predictors = NULL,
class = NULL,
barheight = 0.5
)
glex_explain(...)Arguments
- object
Object of class
glexcontaining prediction components and data to be explained.- id
(
integer(1)) Row ID of the observation to be explained inobject$x.- threshold
(
numeric(1): NULL) Terms whose contribution is at or below this are aggregated under a"Remaining terms"label. The defaultNULLuses 2.5% of the largest absolute contribution in each panel; set0to show all terms.- max_interaction
(
integer(1): NULL) Terms of a higher degree are aggregated under the"Remaining terms"label.- predictors
(
character: NULL) Vector of column names in$xto restrict the plot to.- class
(
character: NULL) For multiclass targets, the target classes to show.- barheight
(
numeric(1): 0.5) Relative height of the bars.- ...
Arguments passed to
plot_shap_decomposition().
Value
A ggplot object.
See also
Other Visualization functions:
plot.glex(),
plot.glex_vi(),
plot_force(),
plot_pdp(),
plot_waterfall()
Examples
set.seed(1)
library(randomPlantedForest)
rp <- rpf(mpg ~ ., data = mtcars[1:26, ], max_interaction = 2)
glex_rpf <- glex(rp, mtcars[27:32, ])
plot_shap_decomposition(glex_rpf, id = 3, predictors = "hp", threshold = 0.01)