giuseppec / iml

iml: interpretable machine learning R package
https://giuseppec.github.io/iml/
Other
492 stars 87 forks source link

Limit number of features in Shapley #171

Open brianfhead opened 3 years ago

brianfhead commented 3 years ago

Hi,

I'm trying to use the Shapley$new function to get Shapley values for an H2O automl model. I've been able to do that with the existing documentation and outside resources. However, I have a relatively large number of features and the plot is too jumbled to read. I cannot figure out a way to limit the number of features (e.g., top 10 or top 20). Is there a way to do that that I've missed in documentation?

Thank you, Brian

ugroempi commented 3 years ago

Hi Brian, you can always extract the results from your object and create a plot without the built-in plot method. The code below gives an example how that can be done, after you created an object mydemo with function Shapley$new. Hope this helps for your next use case. Best, Ulrike (who also struggles with the ?R6Class approach of the package)

phis <- mydemo$results$phi
names(phis) <- mydemo$results$feature
par(mar=c(5, 10, 4, 2)+0.1) # for wide enough left margin
barplot(sort(phis), horiz=TRUE, las=1)
## pick features e.g. by a limit for the absolute value of phis
barplot(sort(phis[abs(phis)>1]), horiz=TRUE, las=1)