1

I'm unable to run shap.initjs() in Azure Data Studio Notebooks. Gave up looking up the issue on Azure community forum or elsewhere.

Visualization omitted, Javascript library not loaded!

shap.initjs()
test_sample = test_x.iloc[:2000,:]
shap_values_sample = explainer.shap_values(test_sample)
shap.force_plot(explainer.expected_value[1], shap_values_sample[1], test_sample, link="logit")

1 Answers1

4

I got a solution for Databricks. You just need to get the HTML out of force_plot and use displayHTML to see the force_plot. Try this:

force_plot = shap.force_plot(xgb_explainer.expected_value, xgb_shap_values, X_test, matplotlib=False)
shap_html = f"<head>{shap.getjs()}</head><body>{force_plot.html()}</body>"
displayHTML(shap_html)

more info: https://towardsdatascience.com/tutorial-on-displaying-shap-force-plots-in-python-html-4883aeb0ee7c

Amarpreet Singh
  • 227
  • 2
  • 11