-1

I would like to use SHAP values to explain the below model:

explainer = shap.DeepExplainer(model, X_train)
shap_values = explainer.shap_values(X_test)

The summary_plot actually works:

shap.summary_plot(shap_values[0], plot_type = 'bar')

but I would like to modify this plot using matplotlib features. In case:

plt = shap.summary_plot(shap_values[0], plot_type = 'bar', show=False)

The plot is shown, and the type of object plt is NoneType, and any modifications are impossible. Do You know how to fore the modification on this plot?

1 Answers1

0

I can suggest the following workaround:

from sklearn.neighbors import KNeighborsClassifier
import shap
from shap import Explanation, KernelExplainer, summary_plot

X, y = shap.datasets.iris(display=True)

knn = KNeighborsClassifier()
knn.fit(X.values, y)
explainer = shap.KernelExplainer(knn.predict_proba, X)
sv = explainer.shap_values(X)

summary_plot(sv[0])
x = plt.gcf()
print(type(x))

matplotlib.figure.Figure

Otherwise, I suggest editing the source code.

Sergey Bushmanov
  • 23,310
  • 7
  • 53
  • 72