Skip to content
Advertisement

SHAP Linear model waterfall with KernelExplainer and LinearExplainer

I am working on binary classification and trying to explain my model using SHAP framework.

I am using logistic regression algorithm. I would like to explain this model using both KernelExplainer and LinearExplainer.

So, I tried the below code from SO here

JavaScript

This threw an error as shown below

AssertionError: Unknown type passed as data object: <class ‘shap.maskers._tabular.Independent’>

How can I explain logistic regression model using SHAP KernelExplainer and SHAP LinearExplainer?

Advertisement

Answer

Calculation-wise the following will do:

JavaScript

enter image description here

Note: KernelExplainer doesn’t support maskers, and in this case either loc or iloc will return the same.

JavaScript

enter image description here

Note here, LinearExplainer‘s result can be provided to waterfall “as-is”

Advertisement