-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster_plot.py
53 lines (49 loc) · 1.99 KB
/
cluster_plot.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
import cluster_init
import matplotlib.pyplot as plt
# plot the data before we implement the algorithm to get forward look
def initial_plot(data):
'''meanlist = [[-5, 5], [3, 3], [5, -5], [12, -2]]
covlist = [[[5, 1], [1, 5]], [[5, 3], [3, 5]], [[4, -2], [-2, 4]], [[5, 0], [0, 1]]]
sizelist = [800, 750, 600, 450]
datashow = cluster_init.datagenerate(meanlist, covlist, sizelist)'''
xshow = [elem[0] for elem in data]
yshow = [elem[1] for elem in data]
plt.plot(xshow, yshow, 'ro')
plt.axis()
plt.show()
# plot the final result for GMM
def result_plot(data, centers, init_centers):
xshow = [elem[0] for elem in data]
yshow = [elem[1] for elem in data]
xcenter = [elem[0,0] for elem in centers]
ycenter = [elem[0,1] for elem in centers]
xinit_center = [elem[0] for elem in init_centers]
yinit_center = [elem[1] for elem in init_centers]
plt.plot(xshow, yshow, 'ro', xcenter, ycenter, 'bs')#xinit_center, yinit_center, 'g^',
plt.axis()
plt.show()
# plot the final result for kmeans
def kmeans_plot(data, centers, init_centers):
xshow = [elem[0] for elem in data]
yshow = [elem[1] for elem in data]
xcenter = [elem[0] for elem in centers]
ycenter = [elem[1] for elem in centers]
xinit_center = [elem[0] for elem in init_centers]
yinit_center = [elem[1] for elem in init_centers]
plt.plot(xshow, yshow, 'ro', xcenter, ycenter, 'bs')#xinit_center, yinit_center, 'g^',
plt.axis()
plt.show()
'''iteration = 10
k = 4
centroids = cluster_init.centers_init(datashow, k)
init_centroids = centroids[:]
for i in range(iteration):
init_centers, centers = kmeans.kmeans(datashow, k, centroids)
xinit_center = [elem[0] for elem in init_centers]
yinit_center = [elem[1] for elem in init_centers]
xcenter = [elem[0] for elem in centers]
ycenter = [elem[1] for elem in centers]
plt.plot(xshow, yshow, 'ro', xinit_center, ycenter, 'g^')
plt.plot(xshow, yshow, 'ro', xcenter, ycenter, 'bs')
plt.axis()
plt.show()'''