Update app.py
Browse files
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
|
73 |
-
plt.figure(figsize=(
|
74 |
-
|
75 |
-
|
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(
|
85 |
-
plt.legend()
|
86 |
st.pyplot(plt)
|
87 |
|
88 |
# Streamlit UI
|
89 |
-
st.write("###
|
90 |
-
|
91 |
-
#
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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("### 特徵重要性數據表")
|