JERNGOC commited on
Commit
708526e
1 Parent(s): 8a2ddd4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -68,28 +68,28 @@ if uploaded_file is not None:
68
  sns.heatmap(corr_matrix, annot=True, cmap='coolwarm', fmt='.2f', linewidths=0.5)
69
  st.pyplot(plt)
70
 
71
- # 繪製特徵重要性圖表
72
- def plot_importance():
73
- plt.figure(figsize=(12, 8))
74
- width = 0.25 # 條形圖寬度
75
- indices = np.arange(len(feature_importance['Feature']))
76
-
77
- plt.bar(indices - width, feature_importance['Linear Regression'], width=width, label='Linear Regression')
78
- plt.bar(indices, feature_importance['CART'], width=width, label='CART')
79
- plt.bar(indices + width, feature_importance['Random Forest'], width=width, label='Random Forest')
80
-
81
- plt.title('Feature Importance Comparison Across Models')
82
  plt.xlabel('Features')
83
  plt.ylabel('Importance')
84
- plt.xticks(indices, feature_importance['Feature'], rotation=45, ha='right')
85
- plt.legend()
86
  st.pyplot(plt)
87
 
88
  # Streamlit UI
89
- st.write("### 特徵重要性對比圖表 (Linear Regression, CART, Random Forest)")
90
-
91
- # 顯示圖表
92
- plot_importance()
 
 
 
 
 
 
 
93
 
94
  # 顯示數據框
95
  st.write("### 特徵重要性數據表")
 
68
  sns.heatmap(corr_matrix, annot=True, cmap='coolwarm', fmt='.2f', linewidths=0.5)
69
  st.pyplot(plt)
70
 
71
+ # 分別繪製各個模型的特徵重要性圖表
72
+ def plot_individual_model(model_name):
73
+ plt.figure(figsize=(10, 6))
74
+ plt.bar(feature_importance['Feature'], feature_importance[model_name])
75
+ plt.title(f'{model_name} Feature Importance')
 
 
 
 
 
 
76
  plt.xlabel('Features')
77
  plt.ylabel('Importance')
78
+ plt.xticks(rotation=45, ha='right')
 
79
  st.pyplot(plt)
80
 
81
  # Streamlit UI
82
+ st.write("### 特徵重要性分析")
83
+
84
+ # 分開顯示三個模型的特徵重要性圖表
85
+ st.write("#### Linear Regression")
86
+ plot_individual_model('Linear Regression')
87
+
88
+ st.write("#### CART (Decision Tree)")
89
+ plot_individual_model('CART')
90
+
91
+ st.write("#### Random Forest")
92
+ plot_individual_model('Random Forest')
93
 
94
  # 顯示數據框
95
  st.write("### 特徵重要性數據表")