Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -70,15 +70,18 @@ if st.button("🔮 開始預測"):
|
|
| 70 |
|
| 71 |
st.subheader("🧠 模型決策解釋圖(SHAP Waterfall plot)")
|
| 72 |
|
|
|
|
| 73 |
shap_values = explainer(input_df)
|
| 74 |
-
fig = shap.plots.waterfall(shap_values[0], show=False)
|
| 75 |
|
| 76 |
-
#
|
| 77 |
-
|
| 78 |
-
text.set_fontname("Noto Sans CJK TC")
|
| 79 |
-
# 修正負號顯示問題
|
| 80 |
-
if text.get_text().startswith('\u2212'):
|
| 81 |
-
text.set_text(text.get_text().replace('\u2212', '-'))
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
st.subheader("🧠 模型決策解釋圖(SHAP Waterfall plot)")
|
| 72 |
|
| 73 |
+
# 計算 SHAP 值
|
| 74 |
shap_values = explainer(input_df)
|
|
|
|
| 75 |
|
| 76 |
+
# 取得 Axes(shap.plots.waterfall 回傳的是 Axes)
|
| 77 |
+
ax = shap.plots.waterfall(shap_values[0], show=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
+
# 設定中文字型
|
| 80 |
+
for text in ax.texts:
|
| 81 |
+
text.set_fontname("Noto Sans CJK TC")
|
| 82 |
+
if text.get_text().startswith('\u2212'):
|
| 83 |
+
text.set_text(text.get_text().replace('\u2212', '-'))
|
| 84 |
+
|
| 85 |
+
# 顯示圖表
|
| 86 |
+
st.pyplot(ax.figure)
|
| 87 |
+
plt.close(ax.figure)
|