Update app.py
Browse files
app.py
CHANGED
@@ -61,28 +61,32 @@ 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 |
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(
|
82 |
|
83 |
# 顯示數據框
|
84 |
-
st.write(
|
85 |
-
st.dataframe(feature_importance
|
86 |
|
87 |
else:
|
88 |
st.error("上傳的檔案中找不到 'target' 欄位,請確認檔案格式。")
|
|
|
61 |
feature_importance = feature_importance.sort_values('Random Forest', ascending=False)
|
62 |
|
63 |
# 繪製特徵重要性圖表
|
64 |
+
def plot_importance():
|
65 |
+
plt.figure(figsize=(12, 8))
|
66 |
+
width = 0.25 # 條形圖寬度
|
67 |
+
indices = np.arange(len(feature_importance['Feature']))
|
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(indices, feature_importance['Feature'], rotation=45, ha='right')
|
77 |
+
plt.legend()
|
78 |
st.pyplot(plt)
|
79 |
|
80 |
# Streamlit UI
|
81 |
st.title("自定義CSV檔案分析 - 特徵重要性分析")
|
82 |
+
st.write("以下是 Linear Regression、CART 和 Random Forest 的特徵重要性對比圖表:")
|
|
|
|
|
|
|
83 |
|
84 |
# 顯示圖表
|
85 |
+
plot_importance()
|
86 |
|
87 |
# 顯示數據框
|
88 |
+
st.write("特徵重要性數據:")
|
89 |
+
st.dataframe(feature_importance)
|
90 |
|
91 |
else:
|
92 |
st.error("上傳的檔案中找不到 'target' 欄位,請確認檔案格式。")
|