1
$\begingroup$

For binary classification, I am getting only a unicolor feature importance plot (i.e., the two classes do not appear individually).

However, for multiclass, I am getting feature importance in different colors. Can someone please explain why I am not getting the same for binary classification?

enter image description here enter image description here


thank you for the answer. But I am doing it for two classes (i.e., binary classification). I have also seen people plotting for two classes (please see the figure below). I want to do the same in my case. In binary classification, the "shap_values = explainer.shap_values(X)" only produces one array in binary classification. However, it produces three arrays in multi-class, as I have three.

enter image description here

$\endgroup$
1
  • $\begingroup$ You are doing it for 3 classes, see the legend. $\endgroup$ Commented Dec 12, 2022 at 18:41

2 Answers 2

2
$\begingroup$

In binary classification, the shap values for the two classes, given a feature and observation, are just opposites of each other, so you get no added information by providing both. You can see this, in the aggregate, in your last plot: the red and blue bars are always the same length. I've seen those two-color plots before, but I suspect they're from an older version of the package (or maybe with more custom code?); I've not seen them generated with current shap.

In multiclass classification, more interesting things happen. In your first plot, feature 38 appears to be great at distinguishing classes 0 and 1, but doesn't move the needle on class 2 much. But feature 42 helps distinguish class 2 a fair bit.

$\endgroup$
1
$\begingroup$

The importance is drawn in one color, because we have 1 class, why should we draw one value in several colors?

For a multiclass task, shap is considered for each class, so the colors are different. However, you can turn a binary classification into a multiclass classification of 2 classes by representing the target vector as 0= [1,0], 1 = [0,1], where [p1,p2] is belonging to classes 0 and 1, and get 2 colors on the shape graph. But it doesn't make much sense, because we just complicate the task and get no benefit (the probability of class 2 is easily expressed from 1 and vice versa)

$\endgroup$
1
  • $\begingroup$ Please see the last section of the question (added) for my response to your answer. thank you $\endgroup$
    – Muppi
    Commented Dec 12, 2022 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.