-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
60 lines (39 loc) · 1.58 KB
/
main.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
import argparse
import numpy as np
from basis_expansion_checker import basis_expansion_chooser
from utils import all_train_fit, model_predict, mse, read_data, save_predictions
from data_analysis import data_analysis
def args_parse():
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--mode', type=str, default=None, choices=["train", "test", None],
help='Choose mode for the model train or test.')
parser.add_argument('--data-analysis', type=bool, default=False,
help='Choose if to generate the visualizations from data analysis.')
args = parser.parse_args()
return args
def predict():
Xtrain, ytrain, Xtest = read_data()
basis = (3, True, True)
w_ls = all_train_fit(Xtrain, ytrain, basis)
ytest_preds = model_predict(Xtest, w_ls, basis)
save_predictions(ytest_preds)
def train():
np.random.seed(23)
Xtrain, ytrain, Xtest = read_data()
# Xtrain, ytrain, Xtest = normalize_data(Xtrain, ytrain, Xtest)
# Xtrain, Xtest = remove_feature(Xtrain, Xtest)
basis = basis_expansion_chooser(Xtrain, ytrain)
w_ls = all_train_fit(Xtrain, ytrain, basis)
train_loss = mse(ytrain, model_predict(Xtrain, w_ls, basis))
print(f"Train Loss: {train_loss}")
ytest_preds = model_predict(Xtest, w_ls, basis)
save_predictions(ytest_preds)
if __name__ == '__main__':
args = args_parse()
print(args)
if args.mode == "train":
train()
elif args.mode == "test":
predict()
if args.data_analysis:
data_analysis()