-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.py
113 lines (98 loc) · 2.88 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import sys
import time
from ml_models.models import Load
from feature_extraction.clustering.dbscan.dbscan_wrapper import cluster_facts
from feature_extraction.clustering.hdbscan.hdbscan_wrapper import HdbscanTrain
from feature_extraction.clustering.k_means.k_means_wrapper import KMeansWrapper
from feature_extraction.preprocessing import save_model
from outputs.output import Log
'''
Improvement:
1 - Commands can be imporoved for this class. Now a little basic
2 - Perhaps clear previous output directories of the models etc.
'''
def cluster_means(arguments):
"""
K means clustering
:param arguments: list[Strings]
:return: None
"""
data_tuple = get_precendent_model(arguments[0])
start = time.time()
KMeansWrapper(data_tuple)
done = time.time()
Log.write('\nClustering time:')
Log.write(done - start)
def cluster_dbscan(arguments):
"""
DBSCAN clustering
:param arguments: list[strings]
:return: None
"""
data_tuple = get_precendent_model(arguments[0])
start = time.time()
cluster_facts(data_tuple, int(arguments[1]), float(arguments[2]))
done = time.time()
Log.write('\nClustering time:')
Log.write(done - start)
def cluster_hdbscan(arguments):
"""
HDBSCAN clustering
:param arguments: list[String]
:return: None
"""
data_tuple = get_precendent_model(arguments[0])
hdb = HdbscanTrain()
start = time.time()
hdb.cluster(data_tuple, int(arguments[1]), int(arguments[2]))
done = time.time()
Log.write('\nClustering time:')
Log.write(done - start)
def parse_precedent(command):
"""
Creates a model of the precedence as binary
:param command: String
:return: None
"""
data = ''
if command == '-facts':
data = 'facts'
elif command == '-decisions':
data = 'decisions'
else:
Log.write('Command not recognized:' + command)
sys.exit(1)
save_model.save(data)
def get_precendent_model(command):
"""
Selects precedence model based on command
:param command: string
:return: None
"""
if command == '-facts':
return Load.load_facts_from_bin()
elif command == '-decisions':
return Load.load_decisions_from_bin()
def process_command(command, arguments):
"""
Maps command to function
:param command: String
:param arguments: List[string]
:return: None
"""
if command == '--dbscan':
cluster_dbscan(arguments)
elif command == '--hdbscan':
cluster_hdbscan(arguments)
elif command == '--kmeans':
cluster_means(arguments)
elif command == '--parse':
parse_precedent(arguments[0])
else:
Log.write('Command not recognized:' + command)
sys.exit(1)
if __name__ == '__main__':
if len(sys.argv) < 2:
Log.write('Please provide more arguments')
sys.exit(1)
process_command(sys.argv[1], sys.argv[2:])