Skip to content
Advertisement

How to get SHAP values for each class on a multiclass classification problem in python

I have the following dataframe:

JavaScript

For which I want to run a classification algorithm in order to predict the 3 classes

So I split my dataset into train and test and I run an xgboost

JavaScript

Now I would like to get the mean SHAP values for each class, instead of the mean from the absolute SHAP values generated from this code:

JavaScript

enter image description here

Also, the plot labels the class as 0,1,2. How can I know to which class from the original do the 0,1 & 2 correspond ?

Because this code:

JavaScript

gives

enter image description here

and this code:

JavaScript

gives

enter image description here

So I am not sure about the legend anymore. Any ideas ?

Advertisement

Answer

By doing some research and with the help of this post and @Alessandro Nesti ‘s answer, here is my solution:

JavaScript

which results in enter image description here

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement