Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
378 views
in Technique[技术] by (71.8m points)

python - Error in shap - AttributeError: module 'shap' has no attribute 'TreeExplainer'

when I'm using:

gb_explainer = shap.TreeExplainer

I get this error:

 AttributeError: module 'shap' has no attribute 'TreeExplainer'

The full code:

    def create_shap_tree_explainer(self):

        self.gb_explainer = shap.TreeExplainer(self.gb_model)
        self.shap_values_X_test =   self.gb_explainer.shap_values(self.X_test)
        self.shap_values_X_train =  self.gb_explainer.shap_values(self.X_train)

The gradient boosting classifier model is:

  gbc_model = Create_Gradient_Boosting_Classifier(X_train, y_train, ps)
question from:https://stackoverflow.com/questions/65643941/error-in-shap-attributeerror-module-shap-has-no-attribute-treeexplainer

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Which SHAP do you use? Please check it.

print(shap.__version__)

Also, did you install SHAP via pip or conda? Where your python access when you run the script? I think, after such checks you will get the answer what is going on.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...