-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain.py
More file actions
36 lines (29 loc) · 1.41 KB
/
train.py
File metadata and controls
36 lines (29 loc) · 1.41 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
import os
import sys
import my_library.Trainer as Trainer # Trainerクラスのインポート
import joblib # モデルの読み込みに使用
# データとモデルの保存先パスを入力させる
preprocessed_train_data_path = input("Enter the path for the preprocessed data:")
model_dump_path_base = input("Enter the path for the directory to save the models:")
# Trainerクラスのインスタンスを作成
trainer = Trainer.Trainer()
# データを読み込む
X, y = trainer.load_data(preprocessed_train_data_path)
# ハイパーパラメータのリストを定義
hyperparameters = [0.1, 1, 10, 100, 1000]
"""
# SVMモデルの学習と保存
for h in hyperparameters:
model_dump_path = os.path.join(model_dump_path_base, f"SVM_{h}.pkl")
trainer.train_SVM(h, X, y)
trainer.dump_model(model_dump_path)
print(f"SVM model with hyperparameter {h} saved to {model_dump_path}")"""
# RandomForestモデルの学習と保存
n_estimators_list = [50, 100, 200, 500]
max_depth_list = [5, 10, 20, 50, None]
for n_estimators in n_estimators_list:
for max_depth in max_depth_list:
model_dump_path = os.path.join(model_dump_path_base, f"RF_n{n_estimators}_d{max_depth}.pkl")
trainer.train_RF(n_estimators, max_depth, X, y)
trainer.dump_model(model_dump_path)
print(f"RandomForest model with n_estimators={n_estimators} and max_depth={max_depth} saved to {model_dump_path}")