-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain.py
84 lines (67 loc) · 3.17 KB
/
train.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import pandas as pd
from pathlib import Path
import dataloader
import models
from config import parse_args
def main():
"""Main function to load data, train machine learning models, and optionally save the trained model
This script reads a CSV dataset, performs data loading and model training based on the user's choice of machine
learning model, and can save the trained model if specified.
"""
args = parse_args()
df_path = Path().cwd() / "data" / f"{args.dataset}.csv"
df = pd.read_csv(df_path)
if args.ml_model_model == "lstm":
data_loader = dataloader.lstm.DataLoader(df, args)
X_train, X_test, y_train, y_test = data_loader.load_data()
model = model.lstm.Model()
model.fit(X_train, y_train)
if args.ml_model == 'prophet':
data_loader = dataloader.neural_prophet.DataLoader(df, args)
df, df_train, df_val = data_loader.load_data()
model = models.prophet.Model(args)
model.fit(df_train, df_val)
if args.ml_model == 'neuralprophet':
data_loader = dataloader.neural_prophet.DataLoader(df, args)
df, df_train, df_val = data_loader.load_data()
model = models.neural_prophet.Model(args)
model.fit(df_train)
if args.ml_model == 'xgboost':
data_loader = data_loader.multi_variate.DataLoader(df, args)
X_train, X_test, y_train, y_test = data_loader.load_data()
model = models.xgboost.Model(args)
model.fit(X_train, y_train)
if args.ml_model == 'lstm_multivariate':
data_loader = data_loader.lstm_multivariate.DataLoader(df, args)
X_train, X_test, y_train, y_test = data_loader.load_data()
model = models.lstm_multivariate.Model(args)
model.fit(X_train, y_train)
if args.ml_model == 'lightgbm':
data_loader = data_loader.multi_variate.DataLoader(df, args)
X_train, X_test, y_train, y_test = data_loader.load_data()
model = models.lightgbm.Model(args)
model.fit(X_train, y_train)
if args.ml_model == 'ensemble_XGBoost_lightgbm':
data_loader = data_loader.multi_variate.DataLoader(df, args)
X_train, X_test, y_train, y_test = data_loader.load_data()
model = models.ensemble.Model(args)
model.fit(X_train, y_train)
if args.ml_model == 'ensemble_XGBoost_lightgbm_lstm_multivariate':
data_loader = data_loader.multi_variate.DataLoader(df, args)
X_train, X_test, y_train, y_test = data_loader.load_data()
model = models.ensemble.Model(args)
model.fit(X_train, y_train)
if args.ml_model == 'ensemble_lightgbm_lstm_multivariate':
data_loader = data_loader.multi_variate.DataLoader(df, args)
X_train, X_test, y_train, y_test = data_loader.load_data()
model = models.ensemble.Model(args)
model.fit(X_train, y_train)
if args.ml_model == 'ensemble_XGBoost_lstm_multivariate':
data_loader = data_loader.multi_variate.DataLoader(df, args)
X_train, X_test, y_train, y_test = data_loader.load_data()
model = models.ensemble.Model(args)
model.fit(X_train, y_train)
if args.enable_save_model:
model.save_model()
if __name__ == "__main__":
main()