forked from yi-ye-zhi-qiu/shaphtml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
31 lines (19 loc) · 720 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from flask import *
import shap
from shap.plots._force_matplotlib import draw_additive_plot
from model import give_shap_plot
app = Flask(__name__)
@app.route('/')
def displayshap():
explainer, shap_values = give_shap_plot()
def _force_plot_html(explainer, shap_values, ind):
force_plot = shap.plots.force(shap_values[ind], matplotlib=False)
shap_html = f"<head>{shap.getjs()}</head><body>{force_plot.html()}</body>"
return shap_html
shap_plots = {}
for i in range(10):
ind = i
shap_plots[i] = _force_plot_html(explainer, shap_values, ind)
return render_template('displayshap.html', shap_plots = shap_plots)
if __name__ == '__main__':
app.run()