Having a binary Classification problem: how would be possible to get the Shap Contribution for variables for a Ranger model?
Sample data:
library(ranger)
library(tidyverse)
# Binary Dataset
df <- iris
df$Target <- if_else(df$Species == "setosa",1,0)
df$Species <- NULL
# Train Ranger Model
model <- ranger(
x = df %>% select(-Target),
y = df %>% pull(Target))
I have tried with several libraries(DALEX
, shapr
, fastshap
, shapper
) but I didnt get any solution.
I wish getting some result like SHAPforxgboost
for xgboost like:
- the output of
shap.values
which is the shap contribution of variables - the
shap.plot.summary
Good Morning!, According to what I have found, you can use
ranger()
with fastshap() as following:Then for example, for variable importance, you can do:
Also, if you want individual predictions, the following is possible:
All this information has been found in here, and there is more to it: https://bgreenwell.github.io/fastshap/articles/fastshap.html Check the link and solve your doubts ! :)