Shapley for Logistic regression?

Viewed 6985

Does shapley support logistic regression models?

Running the following code i get:

logmodel = LogisticRegression()
logmodel.fit(X_train,y_train)
predictions = logmodel.predict(X_test)
explainer = shap.TreeExplainer(logmodel )

Exception: Model type not yet supported by TreeExplainer: <class 'sklearn.linear_model.logistic.LogisticRegression'>

P.S. You are supposed to use a different explainder for different models

3 Answers

Shap is model agnostic by definition. It looks like you have just chosen an explainer that doesn't suit your model type. I suggest looking at KernelExplainer which as described by the creators here is

An implementation of Kernel SHAP, a model agnostic method to estimate SHAP values for any model. Because it makes not assumptions about the model type, KernelExplainer is slower than the other model type specific algorithms.

The documentation for Shap is mostly solid and has some decent examples.

explainer = shap.LinearExplainer(logmodel) should work as Logistic Regression is a linear model.

Logistic Regression is a linear model, so you should use the linear explainer.

Related