-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_app.py
More file actions
69 lines (52 loc) · 2.46 KB
/
Copy pathmain_app.py
File metadata and controls
69 lines (52 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import streamlit as st
import pandas as pd
from sklearn.model_selection import train_test_split
st.title('機械学習アプリケーション')
uploaded_file = st.file_uploader("ファイルをアップロードしてください!")
if uploaded_file is not None:
df = pd.read_csv(uploaded_file)
# dfちゃんと読み込んむか
#st.write(df.columns)
st.divider()
st.title('データの準備')
features = st.multiselect('特徴量の選択',
df.columns.tolist(),
df.columns.tolist())
target = st.selectbox('ターゲットの選択',
df.columns.tolist())
#テストデータを分ける
test_size = st.slider('テストデータのサイズ',0.0, 1.0, 0.5)
df_train,df_test = train_test_split(df,
test_size=test_size,
random_state=1)
st.divider()
st.title('モデリング')
model_option = st.selectbox(
'モデルを選択',
['決定木','ランダムフォーレスト','プースティング決定木']
)
if model_option == '決定木':
from sklearn.tree import DecisionTreeClassifier
model = DecisionTreeClassifier(max_depth=4)
elif model_option == 'ランダムフォーレスト':
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=200,
max_depth=4,
random_state=1)
elif model_option == 'プースティング決定木':
from sklearn.ensemble import GradientBoostingClassifier
model = GradientBoostingClassifier(n_estimators=200,
max_depth=4,
random_state=1)
#st.write(model)
button = st.button('学習開始')
if button:
model.fit(df_train[features],df_train[target])
st.divider()
st.title('評価する')
pred_train = model.predict(df_train[features])#学習データ予測
pred_test = model.predict(df_test[features])#テストデータ予測
st.write('F1スコア(0~1:1であればあるほど良い)')
from sklearn.metrics import f1_score
st.write('学習データ:',f1_score(df_train[target],pred_train))
st.write('テストデータ:',f1_score(df_test[target],pred_test))