Why is there no base_values attribute in shap_values to solve the problem

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

Guess you like

Origin blog.csdn.net/TTritium/article/details/126350059