hibana2077 commited on
Commit
9aaee22
·
1 Parent(s): 79883fe

Upload 2 files

Browse files
Files changed (2) hide show
  1. main.py +88 -0
  2. requirements.txt +6 -0
main.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ '''
2
+ Author: hibana2077 hibana2077@gmail.com
3
+ Date: 2024-01-02 21:43:38
4
+ LastEditors: hibana2077 hibana2077@gmail.com
5
+ LastEditTime: 2024-01-03 18:23:40
6
+ FilePath: \hayabusa\src\main.py
7
+ Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
8
+ '''
9
+ from operator import index
10
+ import streamlit as st
11
+ import plotly.express as px
12
+ from ydata_profiling import ProfileReport
13
+ import pandas as pd
14
+ import pickle
15
+ import time
16
+ import ydata_profiling
17
+ from streamlit_pandas_profiling import st_profile_report
18
+ import os
19
+
20
+ if os.path.exists('./dataset/') == False:
21
+ os.mkdir('./dataset/')
22
+ if os.path.exists('./model/') == False:
23
+ os.mkdir('./model/')
24
+ if os.path.exists('./pipeline/') == False:
25
+ os.mkdir('./pipeline/')
26
+
27
+ with st.sidebar:
28
+ st.title("AutoML")
29
+ choice = st.radio("Navigation", ["Upload","Profiling","Modelling", "Download"])
30
+ st.info("This project application helps you build and explore your data.")
31
+
32
+ if choice == "Upload":
33
+ st.title("Upload Your Dataset")
34
+ file = st.file_uploader("Upload Your Dataset")
35
+ if file:
36
+ df = pd.read_csv(file, index_col=None)
37
+ df.drop("Unnamed: 0", axis=1, inplace=True)
38
+ df.to_csv('dataset.csv', index=None)
39
+ st.dataframe(df)
40
+ st.session_state['df'] = df
41
+
42
+ if choice == "Profiling":
43
+ st.title("Exploratory Data Analysis")
44
+ df:pd.DataFrame = st.session_state['df']
45
+ pr = ProfileReport(df, title="Profiling Report")
46
+ st_profile_report(pr)
47
+
48
+ if choice == "Modelling":
49
+ df:pd.DataFrame = st.session_state['df']
50
+ chosen_target = st.selectbox('Choose the Target Column', df.columns)
51
+ ml_task = st.selectbox('Choose the ML Task', ['Classification', 'Regression'])
52
+ if st.button('Run Modelling'):
53
+ if ml_task == 'Classification':
54
+ from pycaret.classification import setup, compare_models, pull, save_model, get_config
55
+ setup(df, target=chosen_target)
56
+ setup_df = pull()
57
+ st.dataframe(setup_df)
58
+ best_model = compare_models(exclude=['lightgbm'])
59
+ compare_df = pull()
60
+ st.dataframe(compare_df)
61
+ save_model(best_model, 'best_model')
62
+ save_model(best_model, f"./model/{chosen_target}_{time.time()}")
63
+ pipeline = get_config('pipeline')
64
+ st.write(pipeline)
65
+ # save the pipeline
66
+ with open('pipeline.pkl', 'wb') as f:
67
+ pickle.dump(pipeline, f)
68
+ else:
69
+ from pycaret.regression import setup, compare_models, pull, save_model
70
+ setup(df, target=chosen_target)
71
+ setup_df = pull()
72
+ st.dataframe(setup_df)
73
+ best_model = compare_models(exclude=['lightgbm'])
74
+ compare_df = pull()
75
+ st.dataframe(compare_df)
76
+ save_model(best_model, 'best_model')
77
+ save_model(best_model, f"./model/{chosen_target}_{time.time()}")
78
+ pipeline = get_config('pipeline')
79
+ st.write(pipeline)
80
+ # save the pipeline
81
+ with open('pipeline.pkl', 'wb') as f:
82
+ pickle.dump(pipeline, f)
83
+
84
+ if choice == "Download":
85
+ with open('best_model.pkl', 'rb') as f:
86
+ st.download_button('Download Model', f, file_name="best_model.pkl")
87
+ with open('pipeline.pkl', 'rb') as f:
88
+ st.download_button('Download Pipeline', f, file_name="pipeline.pkl")
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ ydata-profiling
2
+ pandas
3
+ pycaret[models]
4
+ streamlit
5
+ numpy
6
+ streamlit-pandas-profiling