[ad_1]

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

```
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_breast_cancer
from shap import TreeExplainer, Explanation
from shap.plots import waterfall
X, y = load_breast_cancer(return_X_y=True, as_frame=True)
idx = 9
model = LogisticRegression().fit(X, y)
background = shap.maskers.Independent(X, max_samples=100)
explainer = KernelExplainer(model,background)
sv = explainer(X.iloc[[5]]) # pass the row of interest as df
exp = Explanation(
sv.values[:, :, 1], # class to explain
sv.base_values[:, 1],
data=X.iloc[[idx]].values, # pass the row of interest as df
feature_names=X.columns,
)
waterfall(exp[0])
```

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?

[ad_2]