add_shap: DEPRECATED - Add SHAP values to (multi-)flashlight

View source: R/add_shap.R

add_shapR Documentation

DEPRECATED - Add SHAP values to (multi-)flashlight

Description

The function calls light_breakdown() for n_shap observations and adds the resulting (approximate) SHAP decompositions as static element "shap" to the (multi)-flashlight for further analyses.

Usage

add_shap(x, ...)

## Default S3 method:
add_shap(x, ...)

## S3 method for class 'flashlight'
add_shap(
  x,
  v = NULL,
  visit_strategy = c("permutation", "importance", "v"),
  n_shap = 200,
  n_max = Inf,
  n_perm = 12,
  seed = NULL,
  use_linkinv = FALSE,
  verbose = TRUE,
  ...
)

## S3 method for class 'multiflashlight'
add_shap(x, ...)

Arguments

x

An object of class "flashlight" or "multiflashlight".

...

Further arguments passed from or to other methods.

v

Vector of variables to assess contribution for. Defaults to all except those specified by "y", "w" and "by".

visit_strategy

In what sequence should variables be visited? By n_perm "permutation" (slow), by "importance" (fast), or as "v" (not recommended).

n_shap

Number of SHAP decompositions to calculate.

n_max

Maximum number of rows in data to consider in the reference data. Set to lower value if data is large.

n_perm

Number of permutations of random visit sequences. Only used if visit_strategy = "permutation".

seed

An integer random seed.

use_linkinv

Should retransformation function be applied? We suggest to keep the default (FALSE) as the values can be retransformed later.

verbose

Should progress bar be shown? Default is TRUE.

Details

We offer two approximations to SHAP: For visit_strategy = "importance", the breakdown algorithm (see reference) is used with importance based visit order. Use the default visit_strategy = "permutation" to run breakdown for multiple random permutations, averaging the results. This approximation will be closer to exact SHAP values, but very slow. Most available arguments can be chosen to reduce computation time.

Value

An object of class "flashlight" or "multiflashlight" with additional element "shap" of class "shap" (and "list").

Methods (by class)

  • add_shap(default): Default method not implemented yet.

  • add_shap(flashlight): Variable attribution to single observation for a flashlight.

  • add_shap(multiflashlight): Add SHAP to multiflashlight.

References

A. Gosiewska and P. Biecek (2019). IBREAKDOWN: Uncertainty of model explanations for non-additive predictive models. ArXiv <arxiv.org/abs/1903.11420>.

Examples

## Not run: 
fit <- lm(Sepal.Length ~ . + Petal.Length:Species, data = iris)
x <- flashlight(model = fit, label = "lm", data = iris, y = "Sepal.Length")
x <- add_shap(x)
is.shap(x$shap)
plot(light_importance(x, type = "shap"))
plot(light_scatter(x, type = "shap", v = "Petal.Length"))
plot(light_scatter(x, type = "shap", v = "Petal.Length", by = "Species"))

## End(Not run)

flashlight documentation built on May 31, 2023, 6:19 p.m.