Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shap python Model type not yet supported by TreeExplainer: class 'sklearn.ensemble._stacking.StackingClassifier

I tried to use Shap (Tree Explainer) for sklearn.ensemble._stacking.StackingClassifier

explainer = shap.TreeExplainer(clf)
shap_values = explainer.shap_values(x)
shap.initjs()
return shap.force_plot(explainer.expected_value[1], shap_values[1], x)

But I got an error: Model type not yet supported by TreeExplainer: <class 'sklearn.ensemble._stacking.StackingClassifier'>

How can I use shap force_plot for sklearn StackingClassifier?

Thank you.

like image 688
Ofir Avatar asked Sep 07 '25 08:09

Ofir


1 Answers

TreeExplainer only works on tree-based models themselves, not on pipelines or metamodels that end with a tree-based model.

If you want interpretability in terms of your original features, you will need to use the base Explainer class (or equivalently, the KernelExplainer class). Unfortunately, this will be approximate and more computationally expensive.

like image 85
eschibli Avatar answered Sep 10 '25 01:09

eschibli