I am working on a Machine Learning model. One of the requests is to explain the models 'decisions' to the business. Therefore I am using Shapley Values (Game Theory).
I found an interesting example on the internet (https://cran.r-project.org/web/packages/iml/vignettes/intro.html), how we can Explain a Single prediction with Shapley (see code in R below). But this is only explaining one single prediction.
- Is it possible to create one explanation for a whole data frame, instead of for just one single row? (for example: having the plot for the whole (test) data frame, instead of only one row).
- If yes, is it academically legit and how can I do that in R?
More information about Shapley values in R (https://www.rdocumentation.org/packages/iml/versions/0.9.0/topics/Shapley)
Thanks in advance!
#Example Shapley #https://cran.r-project.org/web/packages/iml/vignettes/intro.html data("Boston", package = "MASS") head(Boston) set.seed(42) #install.packages("iml") library("iml") library("randomForest") data("Boston", package = "MASS") rf = randomForest(medv ~ ., data = Boston, ntree = 50) # We create a Predictor object, that holds the model and the data. # The iml package uses R6 classes: New objects can be created by calling Predictor$new() X = Boston[which(names(Boston) != "medv")] predictor = Predictor$new(rf, data = X, y = Boston$medv) # Feature Importance ## Shifting each future, and measring how much the performance drops ## imp = FeatureImp$new(predictor, loss = "mae") plot(imp) # Shapley value. Assume that for 1 data point, the feature values play a game together, in which # they get the prediction as payout. Tells us how fairly distibute the payout among the feature values. View(X) shapley = Shapley$new(predictor, x.interest = X[1,]) shapley$plot() # Reuse the object to explain other data points shapley$explain(x.interest = X[2,]) shapley$plot() # Results in data.frame form can be extracted like this: results = shapley$results head(results)