代码部分
import random
import math
import numpy as np
import operator
def get_distance(x1, x2): # 得到两点之间的距离
dist = [x - y for x, y in zip(x1, x2)]
distance=0;
for i in dist:
distance+=i*i
return math.sqrt(distance)
def get_center(cluster):
return sum(np.array(cluster)) / len(cluster)
def k_means(DataSet,k,center_point):#聚类算法
if center_point == list():
number1=random.sample(range(len(DataSet)),k);
center_point = [DataSet[i] for i in number1]
print(center_point)#求初始的随机聚类中心
middle = [] # 建立暂时存放数据
for i in range(k):
temp = []
middle.append(temp)
for i in DataSet: # 计算每个点到中心点的距离
temp =