Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python shap values
import sklearn
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.model_selection import train_test_split
import numpy as np
import shap
# select a set of background examples to take an expectation over
background = np.array(data)
model = sklearn.linear_model.LinearRegression()[:,1:], data.iloc[:,0])
# explain predictions of the model on four images
e = shap.LinearExplainer(model, data.iloc[:,1:])
#explainer = shap.KernelExplainer(model, X_train, link="logit")
shap_values = e.shap_values(np.array(data.iloc[:,1:]))
shap.summary_plot(shap_values, -np.array(data.iloc[:,1:]))
explainer = shap.Explainer(model, data.iloc[:,1:])

This comment has been minimized.

Copy link
Owner Author

@thistleknot thistleknot commented May 2, 2021


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment