'Plotly Dash: How to integrate SHAP values

I am trying to make a model explainer page using Plotly Dash with information from shap values. But I don't know how to get the output from Shap

Here is the code:

#load data & model
cat_model = pickle.load(open('cat-model.saved', 'rb'))

PREPROCESS_DIR = "preprocess-data"
X_test = pickle.load(open(PREPROCESS_DIR+'/X_test_60k.saved', 'rb'))
y_test = pickle.load(open(PREPROCESS_DIR+'/y_test_60k.saved', 'rb'))

explainer = shap.TreeExplainer(cat_model)
shap_values = explainer.shap_values(X_test)


# visualize the first prediction's explanation

shap_html = shap.force_plot(explainer.expected_value, shap_values[:1000,:], X_test.iloc[:1000,:])
    
    
# TODO: Build and run dash app
app = dash.Dash(__name__)
app.config.suppress_callback_exceptions = True

app.layout = html.Div([
    html.H1('Model Explainer', style={'textAlign':'center','color':'#503D36','fontSize':'30px'}),

    html.Div([shap_html], id='output-shap')
])


if __name__ == '__main__':
    app.run_server(debug=True)


Solution 1:[1]

Use explainerdashboard library. It allows you to investigate SHAP values, permutation importances, interaction effects, partial dependence plots, all kinds of performance plots, and even individual decision trees inside a random forest.

https://explainerdashboard.readthedocs.io/en/latest/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Daniel