-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
78 lines (60 loc) · 2.14 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
import argparse
import pickle
from utils.data_process import DataProcess
from models.random_forest_classifier import RandomForestModel
from models.decision_tree_classifier import DecisionTreeModel
from models.neural_net import NeuralNet
from models.conv_net import ConvNet
from models.xgb import XGB
def parse_args(parser):
parser.add_argument('-m', '--model', type = str, choices=['rfc', 'dtc', 'nn', 'cnn', 'xgb'], help = "specify a model type", required = True)
parser.add_argument('-p', '--pickle', type = str, choices=['load'], help = "specify to use pickled files")
args = parser.parse_args()
return args
if __name__ == "__main__":
print("Starting")
parser = argparse.ArgumentParser()
args = parse_args(parser)
model_tag = args.model
model = None
dataset = None
labels = None
conv_dataset = None
accuracy = 0
if(args.pickle != None):
dataset = pickle.load( open( "data/dataset.p", "rb" ))
labels = pickle.load( open( "data/labels.p", "rb" ))
conv_dataset = pickle.load( open( "data/conv_dataset.p", "rb" ))
else:
files_path = 'data/FlowCasesDeidentify120519'
print("Starting Data Process")
dp = DataProcess(files_path)
dp.data_process()
dp.conv_process()
dataset = dp.dataset
labels = dp.labels
conv_dataset = dp.conv_dataset
print("done data process")
print(model_tag)
if model_tag == 'rfc':
print("creating model")
model = RandomForestModel(dataset, labels)
model.train()
accuracy = model.test()
elif model_tag == 'dtc':
model = DecisionTreeModel(dataset, labels)
model.train()
accuracy = model.test()
elif model_tag == 'nn':
model = NeuralNet(dataset, labels)
accuracy = model.test()
elif model_tag == 'cnn':
model = ConvNet(conv_dataset, labels)
accuracy = model.test()
elif model_tag == 'xgb':
model = XGB(dataset, labels)
model.train()
accuracy = model.test()
model.crossval()
# model.gridSearch()
print("Selected model accuracy is: " + str(accuracy))