JERNGOC commited on
Commit
d74d254
·
verified ·
1 Parent(s): 708526e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -0
app.py CHANGED
@@ -8,6 +8,7 @@ from sklearn.linear_model import LinearRegression
8
  from sklearn.tree import DecisionTreeClassifier
9
  from sklearn.ensemble import RandomForestClassifier
10
  from sklearn.preprocessing import StandardScaler
 
11
 
12
  # 讓使用者上傳 CSV 檔案
13
  uploaded_file = st.file_uploader("上傳一個 CSV 檔案", type="csv")
@@ -95,5 +96,20 @@ if uploaded_file is not None:
95
  st.write("### 特徵重要性數據表")
96
  st.dataframe(feature_importance)
97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  else:
99
  st.error("上傳的檔案中找不到 'target' 欄位,請確認檔案格式。")
 
8
  from sklearn.tree import DecisionTreeClassifier
9
  from sklearn.ensemble import RandomForestClassifier
10
  from sklearn.preprocessing import StandardScaler
11
+ from io import BytesIO
12
 
13
  # 讓使用者上傳 CSV 檔案
14
  uploaded_file = st.file_uploader("上傳一個 CSV 檔案", type="csv")
 
96
  st.write("### 特徵重要性數據表")
97
  st.dataframe(feature_importance)
98
 
99
+ # 讓使用者下載特徵重要性的 Excel 檔案
100
+ def to_excel(df):
101
+ output = BytesIO()
102
+ writer = pd.ExcelWriter(output, engine='xlsxwriter')
103
+ df.to_excel(writer, index=False, sheet_name='Feature Importance')
104
+ writer.save()
105
+ processed_data = output.getvalue()
106
+ return processed_data
107
+
108
+ excel_data = to_excel(feature_importance)
109
+ st.download_button(label='下載特徵重要性數據為 Excel 檔案',
110
+ data=excel_data,
111
+ file_name='feature_importance.xlsx',
112
+ mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
113
+
114
  else:
115
  st.error("上傳的檔案中找不到 'target' 欄位,請確認檔案格式。")