File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change 11
11
import random
12
12
13
13
14
+ class Cluster :
15
+
16
+ def __init__ (self ):
17
+ self .x = []
18
+ self .y = []
19
+ self .cx = None
20
+ self .cy = None
21
+
22
+
23
+ def kmean_clustering (rx , ry , nc ):
24
+
25
+ minx , maxx = min (rx ), max (rx )
26
+ miny , maxy = min (ry ), max (ry )
27
+
28
+ clusters = [Cluster () for i in range (nc )]
29
+
30
+ for c in clusters :
31
+ c .cx = random .uniform (minx , maxx )
32
+ c .cy = random .uniform (miny , maxy )
33
+
34
+ return clusters
35
+
36
+
14
37
def calc_raw_data ():
15
38
16
39
rx , ry = [], []
@@ -33,7 +56,14 @@ def main():
33
56
34
57
rx , ry = calc_raw_data ()
35
58
36
- plt .plot (rx , ry , "x" )
59
+ ncluster = 2
60
+ clusters = kmean_clustering (rx , ry , ncluster )
61
+
62
+ for c in clusters :
63
+ print (c .cx , c .cy )
64
+ plt .plot (c .cx , c .cy , "x" )
65
+
66
+ plt .plot (rx , ry , "." )
37
67
plt .show ()
38
68
39
69
You can’t perform that action at this time.
0 commit comments