nb.ipynb
import xgboost as xgb
import shap
import pandas as pd

data = pd.read_csv("data.csv")
X, y = data[features], data[[target]]

clf = xgb.XGBClassifier(tree_method="gpu_exact")
clf.fit(X, y)
nb.ipynb

%%time

xgb_explainer = shap.TreeExplainer(clf,)
shap_values = xgb_explainer.shap_values(X)

Wall time: 21min 37s
nb.ipynb
%%time

booster = clf.get_booster()

shap_values = booster.predict(xgb.DMatrix(X), 
                              pred_contribs=True)
# Remove the bias column
shap_values = shap_values[:, :-1]

Wall time: 1.4 s