-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
95 lines (74 loc) · 2.19 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
from src.dbscan import dbscan
from src.kmeans import kmeans
from src.kmedoids import kmedoids
from getopt import getopt, GetoptError
from sys import argv
from csv import DictReader as CSVDictReader
option_templates = [
"data=",
"dbscan",
"eps=",
"min_pts=",
"kmeans",
"k=",
"kmedoids",
"x=",
"y="
]
try:
options, _ = getopt(argv[1:], "", option_templates)
except GetoptError:
print("Error!")
exit(2)
data = None
algorithm_type = None
eps = None
min_pts = None
k = None
x_label = None
y_label = None
for option, argument in options:
if option == "--data":
# Load data
with open(argument, mode="r") as csv_file:
csv_reader = CSVDictReader(csv_file)
data = [row for row in csv_reader]
elif option in ["--dbscan", "--kmeans", "--kmedoids"]:
algorithm_type = option[2:]
elif option == "--eps":
eps = float(argument)
elif option == "--min_pts":
min_pts = int(argument)
elif option == "--k":
k = int(argument)
elif option == "--x":
x_label = argument
elif option == "--y":
y_label = argument
else:
print("Unknown option: {}".format(option))
exit(2)
if data == None:
print("No data! Use --data <path-to-your-data> options. Make sure it\'s CSV.")
exit(2)
if algorithm_type == "dbscan":
if min_pts == None:
print("DBSCAN needs minimum points. Use --min_pts <minimum-points>. Make sure it\'s integer.")
exit(2)
if eps == None:
print("DBSCAN needs epsilon. Use --eps <epsilon>. Make sure it\'s float.")
exit(2)
dbscan(data, eps, min_pts, x_label, y_label)
elif algorithm_type == "kmeans":
if k == None:
print("K-means needs k. Use --k <k-value>. Make sure it\'s integer.")
exit(2)
kmeans(data, k, x_label, y_label)
elif algorithm_type == "kmedoids":
if k == None:
print("K-moloids needs k. Use --k <k-value>. Make sure it\'s integer.")
exit(2)
kmedoids(data, k, x_label, y_label)
else:
print("Available algorithm: --dbscan; --kmeans; --kmedoids")
exit(2)