Shapley for Logistic regression?
Asked Answered
A

3

7

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

Aquacade answered 27/2, 2020 at 13:26 Comment(0)
R
6

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.

Roughandtumble answered 27/2, 2020 at 13:52 Comment(2)
Ah i see. Thanks, this was simpler than i though, i appreciate itAquacade
No problem. Glad it helped.Roughandtumble
C
5

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

Cynthiacynthie answered 21/12, 2020 at 10:59 Comment(1)
It does, but only if there are two classes.Chiccory
A
0

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

Asbestos answered 17/12, 2020 at 3:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.