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()

Full Model representation of Logistic Regression
Partial Model logistic regression
import shap
masker = shap.maskers.Independent(data = X_test)
model = LogisticRegression(random_state = 1), Y_train)
explainer = shap.LinearExplainer(model, masker=masker)
shap_values = explainer(X_test)
Graph showing the extent to which each feature affect the output
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