-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception: Model type not yet supported by TreeExplainer: <class 'sklearn.pipeline.Pipeline'> #1373
Comments
Your model is actually a pipeline (usually a sequence of preprocessing operations in sklearn followed by the actual classifier). |
@erickrf is right. If you need to explain a whole pipeline I recommend using a model agnostic approach, which under the new API can be |
Thanks @erickrf & @slundberg , I'm getting the following error Exception Traceback (most recent call last) ~\Anaconda3\lib\site-packages\shap\explainers_explainer.py in init(self, model, masker, link, algorithm, output_names) Exception: The passed model is not callable and is not any known model type: Pipeline(memory=None, |
I think with model agnostic explainer you need to pass a function responsible for giving predictions not the model itself. Try: At least it worked for me with KernelExplainer in ver 0.35 |
Thanks @Lamiane I'm getting error in shap_values = explainer(X_train) |
I don't know what your data is and how your code exactly works but I assume It seems that the problem is raised by the |
I tried the workaround using but I am receiving warnings that say: Compilation is falling back to object mode WITH looplifting enabled because Function "_build_fixed_multi_output" failed type inference due to: non-precise type pyobject and Compilation is falling back to object mode WITHOUT looplifting enabled because Function "_build_fixed_multi_output" failed type inference due to: Cannot determine Numba type of <class 'numba.core.dispatcher.LiftedLoop'> I'm not sure what these mean. |
@slundberg Could you please provide a brief code example of how shap can be made to work with a sklearn Pipeline object ? I reviewed the shap documentation, but may have missed it. |
I solved this problem like this explainer = shap.TreeExplainer(pipe.named_steps["model"])
shap_values = explainer.shap_values(pipe[:-1].transform(X_tr))
shap.force_plot(explainer.expected_value, shap_values[0,:], X.iloc[0,:]) |
@slundberg I believe my above answer closed the issue, shall we close it? |
quick question .. |
i solved this problem like this explainer = shap.Explainer(vr.predict, test) |
I'm getting the following error when i executed the TreeExplainer, could you help on this.
clf = Pipeline(steps=[('preprocessor', transformations),
('classifier', RandomForestRegressor(max_depth=6, random_state=0))])
model = clf.fit(X_train, Y_train)
explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X_train)
Exception: Model type not yet supported by TreeExplainer: <class 'sklearn.pipeline.Pipeline'>
The text was updated successfully, but these errors were encountered: