-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
92 lines (80 loc) · 2.56 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import sys
from dataset import Dataset
from classificationmodel import ClassificationModel as cm
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
# main function
if __name__ == "__main__":
# checking number of args
if len(sys.argv) < 3:
print("Usage: python main.py [-create dataset_binary C] [-export export_path] [-cv folds_num] [-import import_path] [-tune dataset_binary]")
exit(1)
# examining options
_create = False
_export = False
_import = False
_tune = False
_cv = False
model = None
dataset_binary_path = ''
export_path = ''
import_path = ''
folds = 5
C = 1
for i in range(0, len(sys.argv)):
if sys.argv[i] == '-create':
_create = True
dataset_binary_path = sys.argv[i+1]
C = float(sys.argv[i+2])
i += 2
if sys.argv[i] == '-import':
_import = True
import_path = sys.argv[i+1]
i += 1
if sys.argv[i] == '-export':
_export = True
export_path = sys.argv[i+1]
i += 1
if sys.argv[i] == '-cv':
_cv = True
folds = int(sys.argv[i+1])
i += 1
if sys.argv[i] == '-tune':
_tune = True
dataset_binary_path = sys.argv[i+1]
i += 1
# if create new model...
if _create:
try:
# reading dataset and extracting features
dset = Dataset.deserialize(dataset_binary_path)
print("Dataset loaded from " + dataset_binary_path)
# building classification model object
model = cm(dset, C)
except NameError:
print('Error while creating model')
# if import model...
if _import:
try:
model = cm.deserialize(import_path)
print("Model imported from " + import_path)
except NameError:
print('Error while importing model')
# if tune model...
if _tune:
dset = Dataset.deserialize(dataset_binary_path)
print("Dataset loaded from " + dataset_binary_path)
cm.tune(dset)
# if export model...
if _export:
try:
model.serialize(export_path)
print("Model exported to " + export_path)
except NameError:
print('Error while exporting model')
# if cross validation model...
if _cv:
try:
model.cross_validation(folds)
except NameError:
print('Error while doing cross validation')