jung-ming commited on
Commit
75c5c29
·
verified ·
1 Parent(s): 1d6070a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -81,15 +81,22 @@ if st.button("🔮 開始預測"):
81
  st.subheader("🧠 模型決策解釋圖(SHAP Waterfall plot)")
82
 
83
  shap_values = explainer(input_df)
84
- ax = shap.plots.waterfall(shap_values[0], show=False)
85
 
86
- # 強制為每個文字物件設定中文字型,避免顯示方塊
87
- if chinese_font_prop:
88
- for text in ax.texts:
89
- text.set_fontproperties(chinese_font_prop)
90
- # 修正負號顯示問題(使用 ASCII 減號)
91
- if text.get_text().startswith('\u2212'):
92
- text.set_text(text.get_text().replace('\u2212', '-'))
 
 
 
 
 
 
 
 
93
 
94
  st.pyplot(ax.figure)
95
  plt.close(ax.figure)
 
81
  st.subheader("🧠 模型決策解釋圖(SHAP Waterfall plot)")
82
 
83
  shap_values = explainer(input_df)
 
84
 
85
+ # 改 feature_names
86
+ feature_name_map = {
87
+ "航線組合數": "Route Count",
88
+ "年": "Year",
89
+ "月": "Month",
90
+ "船舶種類_編碼": "Ship Type Code"
91
+ }
92
+ shap_values.feature_names = [feature_name_map.get(f, f) for f in shap_values.feature_names]
93
+
94
+ ax = shap.plots.waterfall(shap_values[0], show=False)
95
+
96
+ # 負號替換
97
+ for text in ax.texts:
98
+ if text.get_text().startswith('\u2212'):
99
+ text.set_text(text.get_text().replace('\u2212', '-'))
100
 
101
  st.pyplot(ax.figure)
102
  plt.close(ax.figure)