I have a Pipeline object for a 3-class classification problem. Because most of the examples I find are for binary classifications, I'm finding a bit difficult to perfectly understand how to get the correct plots for each sample.
So, I have this code (pipe_model is my Pipeline object, previously fitted, and X_train and X_test are my train and test data, respectively):
import shap
explainer = shap.KernelExplainer(pipe_model.predict_proba, X_train, link="logit")
shap_values = explainer.shap_values(X_test, nsamples="auto")
I want a plot for each sample in my X_test. I know that somehow explainer.expected_value and shap_values will have 3 parts for each class I'm classifying. So, for example, if I wanted to plot the importance for the first 2 samples of X_test, I was doing this:
shap.force_plot(explainer.expected_value[0], shap_values[0][0,:], X_test.iloc[0,:], link="logit")
shap.force_plot(explainer.expected_value[1], shap_values[1][0,:], X_test.iloc[1,:], link="logit")
I played a bit around with the indexes in expected_value and shap_values and the plots change in a why I cannot explain. Can someone please let me know how I should plot the force_plot for each sample, for each class?