-
Notifications
You must be signed in to change notification settings - Fork 2
/
runClassifier.py
59 lines (44 loc) · 1.46 KB
/
runClassifier.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
import sys
import getopt
import os
from features import extractFeatures
from train import trainRandomForrest, trainXGBoost, RANDOM_FORREST_CLASSIFIER, XGBOOST_MODEL
from test import testRandomForrest, testXGBoost
def main():
argv = sys.argv[1:]
# print(argv)
try:
opts, args = getopt.getopt(argv, 'i:o:c:', [])
print(opts)
except getopt.GetoptError as err:
print(str(err))
sys.exit(2)
inDir = ''
outDir = ''
classifier = ''
for opt, arg in opts:
if opt == '-i':
if not os.path.exists(arg):
print('Aborting, can not find infile:', arg)
sys.exit(2)
inDir = arg
elif opt == '-o':
outDir = arg
else:
if arg not in ('xgboost', 'randomforrest'):
print('Aborting, invalid classifier must be "xgboost" or "randomforrest"')
sys.exit(2)
classifier = arg
extractFeatures(inDir)
if classifier == 'randomforrest':
if not os.path.exists(RANDOM_FORREST_CLASSIFIER):
print('Could not find trained RandomForrestClassifier')
sys.exit(2)
testRandomForrest('features.csv', outDir)
if classifier == 'xgboost':
if not os.path.exists(XGBOOST_MODEL):
print('Can not find trained XGBoost model')
sys.exit(2)
testXGBoost('features.csv', outDir)
if __name__ == "__main__":
main()