additive_shap {kernelshap}R Documentation

Additive SHAP

Description

Exact additive SHAP assuming feature independence. The implementation works for models fitted via

Usage

additive_shap(object, X, verbose = TRUE, ...)

Arguments

object

Fitted model object.

X

Dataframe with rows to be explained. Will be used like predict(object, newdata = X, type = "terms").

verbose

Set to FALSE to suppress messages and the progress bar.

...

Currently unused.

Details

The SHAP values are extracted via predict(object, newdata = X, type = "terms"), a logic heavily inspired by fastshap:::explain.lm(..., exact = TRUE). Models with interactions (specified via : or *), or with terms of multiple features like log(x1/x2) are not supported.

Value

An object of class "kernelshap" with the following components:

Examples

# MODEL ONE: Linear regression
fit <- lm(Sepal.Length ~ ., data = iris)
s <- additive_shap(fit, head(iris))
s

# MODEL TWO: More complicated (but not very clever) formula
fit <- lm(
  Sepal.Length ~ poly(Sepal.Width, 2) + log(Petal.Length) + log(Sepal.Width),
  data = iris
)
s <- additive_shap(fit, head(iris))
s

[Package kernelshap version 0.5.0 Index]