Shap values with tidymodels and SHAPforxgboost

I'm having the same issue found in https://community.rstudio.com/t/shap-values-with-tidymodels

The shap values are reverse to what is expected of the meaning of my variables.

Someone can please provide any comment?

I found out that doing the simple follow step would invert all directions of SHAP value and result in the expected figure:

dm_shap$value = - dm_shap$value

image

Also, library(shapviz) produces that expected results with better looking graphics.

So tidymodels chooses the first level of a binary factor as the event of interest. The happens in yardstick and there are options to invert that. I don't know if that is the issue but it sounds like a good possibility. Perhaps give that a try?

Good idea. Maybe you are thinking of options(yardstick.event_first = FALSE).

I traced back the function calls looking for an option to invert that but no sign of such.
In fact, library(SHAPforxgboost) only encapsulates SHAP values computed by library(xgboost) as xgboost::predict(model, X, predcontrib = TRUE)` which do not give any option.

Then, I changed by hand the level value to positive case (has diabetes) as 0 and negative to 1 (does not have diabetes) and plotting now worked as expected.

Line changed is data$diabetes <- as.factor(abs(data$diabetes-1)).

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.