-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcluster.py
More file actions
77 lines (65 loc) · 1.36 KB
/
cluster.py
File metadata and controls
77 lines (65 loc) · 1.36 KB
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
import numpy as np
from scipy.cluster.vq import kmeans2, whiten
import json
with open("dummy1.json") as f:
data = json.load(f)
print(type(data))
i = 0
usr_prob = np.ndarray((1334,5))
for usr in data:
usr_prob[i] = usr["problems"]
i += 1
# print(i)
# print(usr_prob)
print(data)
# usr_data = np.array(usr_prob)
x, y = kmeans2(whiten(usr_prob), 5, iter = 20)
# y.dtype = np.int64
# print(type(y))
# print(x)
print(y)
print(len(y))
#
# # print(data["coordinates"]["lat"])
#
j = 0
lat = np.ndarray((1334,1))
long = np.ndarray((1334,1))
locn_cluster = {"lat" : [],
"long" : [],
"cluster" : []}
print(len(y))
for usr in data:
locn = usr["coordinate"]
# print(locn)
locn_cluster["lat"].append(locn["lat"])
locn_cluster["long"].append(locn["long"])
locn_cluster["cluster"].append(y[j])
# print()
j += 1
#
#
# print(locn_cluster)
#
print(len(locn_cluster["lat"]))
print(len(locn_cluster["long"]))
print(len(locn_cluster["cluster"]))
#
#
# # print(lat)
#
#
# # usr_lbl = {"lat" : lat,
# # "long" : long,
# # "cluster" : y}
# # print(usr_lbl["lat"])
#
#
# json = [json.dumps(locn_cluster) for k,v in locn_cluster.items()]
# # print(json)
# f = open("locn_cluster", "w")
# f.write(json)
# f.close()
with open("data.json", "w") as outfile:
json.dump(locn_cluster, outfile)
# r = json.dumps(locn_cluster)