Source of problem:
In the process of learning shap, I want to draw waterfall and bar diagrams, but encounter the following error:
My shap_values refer to the example of catboost tutorial in the official document of shap
Problem summary :
My shap_values are just an array, not real shap_values (no base_values attribute, nor an explanation object)
problem solved:
Refer to the Shap official documentation on the use of bar to find some code differences
Documentation by example for shap.plots.bar — SHAP latest documentation
区别:shap_values = explainer(X)与 shap_values = explainer.shap_values(X)
The given object is different, what shap_values = explainer(X) gives is an explanation object
After I modified the code, it can be used successfully
shap.plots.bar(explainer(X_train))
shap.plots.waterfall(explainer(X_train)[0])
I hope useful to you