I have a small dataset with 816 rows and 8 numerical features.
The target variable is categorical, with 4 different categories.
I trained a XGB model on the dataset and after that I try to use SHAP for feature importances.
I am using this code:
explainer = shap.TreeExplainer(model, X_test)
shap_values = explainer(X_test_scaled_df)
By running the code above I obtain an output shap_values
with shape different from what I should get according to the documentation or according to examples online. The shape is (816,8,4).
816 is the number of samples in the dataset, 8 is the number of features, and 4 is the number of classes.
In order to plot the feature importances for class 0 I need to run:
shap.plots.bar(shap_values[:,:,0])
but this is different from what it is written in documentation or in examples online where they always say that it should be sufficient to run:
shap.plots.bar(shap_values)
Why is that so?
Furthermore, what if I want a single plot that shows the SHAP values for all the classes in a single figure?
The version that I am using of shap is 0.45.1, but I tried also more updated version of the library and I obtain the same results.