Skip to content

Commit

Permalink
Merge pull request #30 from Harold-Ran/patch-2
Browse files Browse the repository at this point in the history
Update K-means_Clustering.py
  • Loading branch information
Dod-o authored Sep 13, 2021
2 parents f4e0d94 + c689701 commit 01f6d6c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Clustering/K-means_Clustering/K-means_Clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def cal_distance(xi, xj):
dist = 0
for col in range(len(xi)):
dist += (xi[col]-xj[col]) ** 2
dist = math.sqrt(dist)
return dist


Expand Down Expand Up @@ -125,8 +126,8 @@ def Adjusted_Rand_Index(group_dict, Ylist, k):
if n in group_dict[i] and n in y_dict[j]:
group_array[i][j] += 1 #如果数据n同时在group_dict的类别i和y_dict的类别j中,group_array[i][j]的数值加一
RI = 0 #定义兰德系数(RI)
sum_i = np.zeros(3) #定义一个数组,用于保存聚类结果group_dict中每一类的个数
sum_j = np.zeros(3) #定义一个数组,用于保存外部标签y_dict中每一类的个数
sum_i = np.zeros(k) #定义一个数组,用于保存聚类结果group_dict中每一类的个数
sum_j = np.zeros(k) #定义一个数组,用于保存外部标签y_dict中每一类的个数
for i in range(k):
for j in range(k):
sum_i[i] += group_array[i][j]
Expand Down Expand Up @@ -189,4 +190,4 @@ def Kmeans(Xarray, k, iters):
group_dict, scores = Kmeans(Xarray, k, iters) #进行k均值聚类
end = time.time() #保存结束时间
print('Time:', end-start)
plt.plot(range(iters), scores) #绘制ARI得分折线图
plt.plot(range(iters), scores) #绘制ARI得分折线图

0 comments on commit 01f6d6c

Please sign in to comment.