(self, datas, k)
return seeds
function:
            kmeans++与kmeans最大不同点就是种子生成算法不同
        params:
            datas 聚类数据
            k   聚类数目
function:
            kmeans++与kmeans最大不同点就是种子生成算法不同
        params:
            datas 聚类数据
            k   聚类数目
function : kmeans ++ 与kmeans最大不同点就是种子生成算法不同 params : datas 聚类数据 k 聚类数目
def rand_seed(self, datas, k):
        '''
        function:
            kmeans++与kmeans最大不同点就是种子生成算法不同
        params:
            datas 聚类数据
            k   聚类数目
        '''
        seeds = [(
            copy(datas[randint(0, len(datas) - 1)]), 0
        )] #初始化种子库 ，随机一个种子
        #获取剩余种子
        for k_iter in range(k - 1):
            ds = [] #种子距离
            for data in datas:
                ds.append(
                    min(self.distance(seed[0], data)
                        for seed in seeds))
            sum_distance = sum(ds)
            rand_distance = random() * sum_distance
            for i in range(len(ds)):
                rand_distance -= ds[i]
                if rand_distance <= 0:
                    seeds.append((copy(datas[i]), k_iter + 1))
                    break
        return seeds
def rand_seed ( self , datas , k ) : seeds = [ ( copy ( datas [ randint ( 0 , len ( datas ) - 1 ) ] ) , 0 ) ] #初始化种子库 ，随机一个种子 #获取剩余种子 for k_iter in range ( k - 1 ) : ds = [ ] #种子距离 for data in datas : ds . append ( min ( self . distance ( seed [ 0 ] , data ) for seed in seeds ) ) sum_distance = sum ( ds ) rand_distance = random ( ) * sum_distance for i in range ( len ( ds ) ) : rand_distance -= ds [ i ] if rand_distance <= 0 : seeds . append ( ( copy ( datas [ i ] ) , k_iter + 1 ) ) break return seeds