Update app.py
Browse files
app.py
CHANGED
@@ -61,32 +61,28 @@ if uploaded_file is not None:
|
|
61 |
feature_importance = feature_importance.sort_values('Random Forest', ascending=False)
|
62 |
|
63 |
# 繪製特徵重要性圖表
|
64 |
-
def plot_importance():
|
65 |
-
plt.figure(figsize=(
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
plt.bar(indices - width, feature_importance['Linear Regression'], width=width, label='Linear Regression')
|
70 |
-
plt.bar(indices, feature_importance['CART'], width=width, label='CART')
|
71 |
-
plt.bar(indices + width, feature_importance['Random Forest'], width=width, label='Random Forest')
|
72 |
-
|
73 |
-
plt.title('Feature Importance Comparison Across Models')
|
74 |
plt.xlabel('Features')
|
75 |
plt.ylabel('Importance')
|
76 |
-
plt.xticks(
|
77 |
-
plt.legend()
|
78 |
st.pyplot(plt)
|
79 |
|
80 |
# Streamlit UI
|
81 |
st.title("自定義CSV檔案分析 - 特徵重要性分析")
|
82 |
-
st.write("
|
|
|
|
|
|
|
83 |
|
84 |
# 顯示圖表
|
85 |
-
plot_importance()
|
86 |
|
87 |
# 顯示數據框
|
88 |
-
st.write("特徵重要性數據:")
|
89 |
-
st.dataframe(feature_importance)
|
90 |
|
91 |
else:
|
92 |
st.error("上傳的檔案中找不到 'target' 欄位,請確認檔案格式。")
|
|
|
61 |
feature_importance = feature_importance.sort_values('Random Forest', ascending=False)
|
62 |
|
63 |
# 繪製特徵重要性圖表
|
64 |
+
def plot_importance(model):
|
65 |
+
plt.figure(figsize=(10, 6))
|
66 |
+
plt.bar(feature_importance['Feature'], feature_importance[model])
|
67 |
+
plt.title(f'{model} Feature Importance')
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
plt.xlabel('Features')
|
69 |
plt.ylabel('Importance')
|
70 |
+
plt.xticks(rotation=45, ha='right')
|
|
|
71 |
st.pyplot(plt)
|
72 |
|
73 |
# Streamlit UI
|
74 |
st.title("自定義CSV檔案分析 - 特徵重要性分析")
|
75 |
+
st.write("選擇一個模型來查看其特徵重要性:")
|
76 |
+
|
77 |
+
# 下拉選擇模型
|
78 |
+
model = st.selectbox("選擇模型", ["Linear Regression", "CART", "Random Forest"])
|
79 |
|
80 |
# 顯示圖表
|
81 |
+
plot_importance(model)
|
82 |
|
83 |
# 顯示數據框
|
84 |
+
st.write(f"{model} 特徵重要性數據:")
|
85 |
+
st.dataframe(feature_importance[['Feature', model]])
|
86 |
|
87 |
else:
|
88 |
st.error("上傳的檔案中找不到 'target' 欄位,請確認檔案格式。")
|