jung-ming commited on
Commit
5510cda
·
verified ·
1 Parent(s): c3454cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
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
- # 強制將所有 label 替換字型
77
- for text in fig.axes[0].texts:
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
- st.pyplot(fig)
84
- plt.close(fig)
 
 
 
 
 
 
 
 
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)