I am trying to use SHAP library on streamlit to draw force_plot, summary_plot, summary_plot_bar and dependance_plot.
But only force_plot is not be displayed as follows:
*force_plot image should be located on top but that place is blank.
- python coding is as follows:
###########
import numpy as np
import pandas as pd
import streamlit as st
import matplotlib.pyplot as plt
import japanize_matplotlib
#Use Random Forest
from sklearn.ensemble import RandomForestRegressor
#SHAP(SHapley Additive exPlanations)
import shap
shap.initjs() # for visualization
X, y = shap.datasets.boston()
clf = RandomForestRegressor(n_estimators=500, n_jobs=-1)
clf.fit(X, y)
explainer = shap.TreeExplainer(clf, X)
shap_values = explainer.shap_values(X)
st.set_option('deprecation.showPyplotGlobalUse', False)
#force_plot
i = 0
shap.force_plot(explainer.expected_value, shap_values[i,:], X.iloc[i,:])
st.pyplot()
#summary_plot_bar
shap.summary_plot(shap_values, X, plot_type="bar")
st.pyplot()
#summary_plot
shap.summary_plot(shap_values, X)
st.pyplot()
#dependance_plot
shap.dependence_plot("LSTAT", shap_values, X)
st.pyplot()
###########################
The image of force_plot is displayed on Jupyter notebook using the same python coding.
I would appreciate it if you could give me some advice.
Thank you.