-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
71 lines (55 loc) · 2.54 KB
/
run.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
import sys
import os
import argparse
import logging
log = logging.getLogger("jigsaw")
import kaggle_jigsaw.util as u
import atexit
import yaml
if __name__ == "__main__":
log = u.set_console_logger(log)
# parameters
# add experiment arguments
parser = argparse.ArgumentParser()
parser.add_argument('--model', choices=["GRU", "LSTM", "CNN", "LGB", "NBSVM", "LSTM_CONV",
"LR", "RIDGE", "ET", "RF", "GBT", "KNN"
] ,
help='Model type to run')
parser.add_argument('--skip_cv', action="store_true", help='skip cv and train on the whole set')
parser.add_argument('--retrain', action="store_true", help='train on the whole set')
parser.add_argument('--shutdown_vm', action="store_true", help='shutdown VM after finishing the run')
parser.add_argument('--num_folds', type=int, default=5, help='number of folds for cross val')
parser.add_argument('--conf', help='number of folds for cross val')
args = parser.parse_args()
log.info("Running with arguments: {}".format(args))
model = args.model
if args.model is None:
conf = yaml.load(open(args.conf,"r"))
model = conf.get("exec_params",{}).get("model_type")
log.debug("model_type = "+ model)
if model is None:
raise ValueError("Model type not configured neither via --model nor in the config")
if model in ["GRU", "LSTM", "CNN", "LSTM_CONV"]:
from kaggle_jigsaw.experiments.NN import NN_experiment
experiment = NN_experiment
if model in ["LR", "RIDGE", "ET", "RF", "GBT", "KNN"]:
from kaggle_jigsaw.experiments.sklearn import sklearn_experiment
experiment = sklearn_experiment
elif model in ["LGB"]:
from kaggle_jigsaw.experiments.lgb import lgb_experiment
experiment = lgb_experiment
elif model in ["NBSVM"]:
from kaggle_jigsaw.experiments.nbsvm import ex_nb_svm
experiment = ex_nb_svm
else:
raise ValueError("unknown model type")
if args.conf is not None:
experiment.add_config(args.conf)
else:
experiment.add_config("conf_template/{}.yaml".format(args.model))
if args.shutdown_vm: atexit.register(u.shutdown_vm)
experiment.run(config_updates={"exec_params":
{"model_type": model,
"skip_cv":args.skip_cv,
"retrain": args.retrain,
"num_folds":args.num_folds}} )