SHAP in Python

Photo by GR Stocks on Unsplash
def get_stats():
X = data3[x_columns]
X_test = X.iloc[1:550,:]
Y_test = data3.iloc[1:550,k-1]
x = X_test
logit_model = sm.Logit(Y_test, sm.add_constant(X_test)).fit()
print(logit_model.summary())

get_stats()
Full Model representation of Logistic Regression
Partial Model logistic regression
import shap
masker = shap.maskers.Independent(data = X_test)
model = LogisticRegression(random_state = 1)
model.fit(X_train, Y_train)
explainer = shap.LinearExplainer(model, masker=masker)
shap_values = explainer(X_test)
shap.plots.waterfall(shap_values[0])
Graph showing the extent to which each feature affect the output
shap.plots.beeswarm(shap_values)
Graph representing the importance of each feature
Partial Model created after logistic regression

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store