Shap: are shap plots accessible outside of jupyter notebooks?

Created on 11 Jul 2019  路  2Comments  路  Source: slundberg/shap

I typically don't run my model from Notebooks. Does shap support non-js plotting backends such as matplotlib?

Most helpful comment

Yes, shap supports matplotlib.

A demo from the readme:

import xgboost
import shap

# load JS visualization code to notebook
shap.initjs()

# train XGBoost model
X,y = shap.datasets.boston()
model = xgboost.train({"learning_rate": 0.01}, xgboost.DMatrix(X, label=y), 100)

# explain the model's predictions using SHAP values
# (same syntax works for LightGBM, CatBoost, and scikit-learn models)
explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X)

# visualize the first prediction's explanation (use matplotlib=True to avoid Javascript)
shap.force_plot(explainer.expected_value, shap_values[0,:], X.iloc[0,:], matplotlib=True)

All 2 comments

Yes, shap supports matplotlib.

A demo from the readme:

import xgboost
import shap

# load JS visualization code to notebook
shap.initjs()

# train XGBoost model
X,y = shap.datasets.boston()
model = xgboost.train({"learning_rate": 0.01}, xgboost.DMatrix(X, label=y), 100)

# explain the model's predictions using SHAP values
# (same syntax works for LightGBM, CatBoost, and scikit-learn models)
explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X)

# visualize the first prediction's explanation (use matplotlib=True to avoid Javascript)
shap.force_plot(explainer.expected_value, shap_values[0,:], X.iloc[0,:], matplotlib=True)

thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gabrielcs picture gabrielcs  路  3Comments

grofte picture grofte  路  4Comments

1vecera picture 1vecera  路  3Comments

saurabhhjjain picture saurabhhjjain  路  3Comments

TdoubleG picture TdoubleG  路  4Comments