#
# A projection pursuit regression (PPR) example
#
# Load the sample data; see ?datasets::mtcars for details
data(mtcars)
# Fit a projection pursuit regression model
fit <- lm(mpg ~ ., data = mtcars)
# Compute approximate Shapley values using 10 Monte Carlo simulations
set.seed(101) # for reproducibility
shap <- explain(fit, X = subset(mtcars, select = -mpg), nsim = 10,
pred_wrapper = predict)
shap
# Compute exact Shapley (i.e., LinearSHAP) values
shap <- explain(fit, exact = TRUE)
shap
# Shapley-based plots
library(ggplot2)
autoplot(shap) # Shapley-based importance plot
autoplot(shap, type = "dependence", feature = "wt", X = mtcars)
autoplot(shap, type = "contribution", row_num = 1) # explain first row of X
Run the code above in your browser using DataLab