# 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_add <- additive_shap(fit, head(iris))
s_add
# Equals kernelshap()/permshap() when background data is full training data
s_kernel <- kernelshap(
fit, head(iris[c("Sepal.Width", "Petal.Length")]), bg_X = iris
)
all.equal(s_add$S, s_kernel$S)
Run the code above in your browser using DataLab