Skip to content

Instantly share code, notes, and snippets.

@marnixkoops
Created April 10, 2019 13:01
Show Gist options
  • Select an option

  • Save marnixkoops/8e8636cb17e55981a71b5cd38f7332ad to your computer and use it in GitHub Desktop.

Select an option

Save marnixkoops/8e8636cb17e55981a71b5cd38f7332ad to your computer and use it in GitHub Desktop.
# %% markdown
# WEER IMPACT
# %%
# SETUP
import pandas as pd
import numpy as np
import pickle
import matplotlib
import matplotlib.pyplot as plt
import shap
shap.initjs()
# %%
# DATA
pickle_in = open('booster.pickle', 'rb')
booster = pickle.load(pickle_in) # Load XGBoost booster object
pickle_in = open('features.pickle', 'rb')
features = pickle.load(pickle_in) # Load features object
# %%
# SHAP VALUE COMPUTATION
explainer = shap.TreeExplainer(booster)
shap_values = explainer.shap_values(features).astype('float64')
# %%
# SHAP ATTRIBUTIONS
shap.summary_plot(shap_values, features, max_display=20, show=False, auto_size_plot=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment