It just hung there when I was trying to get the shap values for a trained RandomForestRegressor rfr through the following code:
explainer_rf = shap.TreeExplainer(rfr)
shap_values_rf = explainer_rf.shap_values(TrX)
It was good with both _xgboost_ and _lightgbm_ though.
Tried with both Spyder and Jupyter but got the same thing.
SHAP version 0.30.1.
OS: win10 64-bit.
I had a similar issue with RandomForestClassifier, while with LightGBM it worked in seconds, with sklearn's RandomForestClassifier it didn't produce anything after several minutes.
@BaboBoyoung What is your scikit-learn version?
TreeExplainer's runtime grows quadratically with the depth of the tree, so it is slower for RF models. I would try and explain just a few samples to get a feel for the runtime. (Solutions would be to limit the RF depth a bit)
TreeExplainer's runtime grows quadratically with the depth of the tree, so it is slower for RF models. I would try and explain just a few samples to get a feel for the runtime. (Solutions would be to limit the RF depth a bit)
I just realized that max_depth is none by default. I tried it from 5-30, the GridSearchCV chose 15 for me. But still shap didn't work for max_depth of 15. However, when I just forced max_depth to be 5 in my RF model, it now works. Thought you would be interested to know @slundberg . Thanks!
I had a similar issue with RandomForestClassifier, while with LightGBM it worked in seconds, with sklearn's RandomForestClassifier it didn't produce anything after several minutes.
@BaboBoyoung What is your scikit-learn version?
My version is 0.21.2.
I think the problem is the depth of trees -- as @slundberg pointed out.
Maybe the most practical solution would be setting approximate=True.
I have normally not had issues with model of depth 15, but I suppose it depends how many trees you have and how filled out they are.
Had a similar issue with SamplingExplainer in version 0.35.0 and Python 3.7.6. Interestingly, I got it working after downgrading to shap 0.34.0. I suppose it's related to the compatibility between shap and python versions.