diff --git a/Clustering/K-means_Clustering/K-means_Clustering.py b/Clustering/K-means_Clustering/K-means_Clustering.py index 5603b9f..b1f6152 100644 --- a/Clustering/K-means_Clustering/K-means_Clustering.py +++ b/Clustering/K-means_Clustering/K-means_Clustering.py @@ -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 @@ -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] @@ -189,4 +190,4 @@ if __name__ == "__main__": group_dict, scores = Kmeans(Xarray, k, iters) #进行k均值聚类 end = time.time() #保存结束时间 print('Time:', end-start) - plt.plot(range(iters), scores) #绘制ARI得分折线图 \ No newline at end of file + plt.plot(range(iters), scores) #绘制ARI得分折线图