02-13-2019 11:29 AM
I am looking to display SHAP plots, here is the code:
import xgboost import shapshap.initjs() # load JS visualization code to notebookX,y = shap.datasets.boston() # train XGBoost model
model = xgboost.train({"learning_rate": 0.01}, xgboost.DMatrix(X, label=y), 100)
explainer = shap.TreeExplainer(model) # explain the model's predictions using SHAP values
shap_values = explainer.shap_values(X)
shap_explain = shap.force_plot(explainer.expected_value, shap_values[0,:], X.iloc[0,:]) # visualize the first prediction's explanation
displayHTML(shap_explain.data) # display plot
However I am receiving the following error:
Any help greatly appreciated!
02-17-2019 10:26 PM
I was finally able to plot them in DataBricks without js
shap_display = shap.force_plot(explainer.expected_value[1], shap_value[1], feat_x.iloc[0, :], matplotlib=True)display(shap_display)
02-17-2019 10:26 PM
I was finally able to plot them in DataBricks without js
shap_display = shap.force_plot(explainer.expected_value[1], shap_value[1], feat_x.iloc[0, :], matplotlib=True)display(shap_display)
01-06-2020 10:23 PM
It is quite good but only works for a single explanation. If you want to apply to multiple samples, force_plot has not been supported yet as in Jan 2020.
02-21-2019 07:27 AM
It also needs to be run on an earlier version of matplotlib
matplotlib: 1.5.3
06-18-2019 06:21 PM
For what it's worth, I got force plots to work in Databricks by copying the bundle.js Javascript from the SHAP package into a hidden cell in the notebook. See https://databricks.com/blog/2019/06/17/detecting-bias-with-shap.html and the notebook that accompanies it.
02-05-2020 08:07 AM
As @Vinh dqvinh87 noted, the accepted solution only works for
force_plot
. For other plots, the following trick works for me:
import matplotlib.pyplot as plt
p = shap.summary_plot(shap_values, test_df, show=False)
display(p)
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group