sf_kmeans.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:kmeans-service 作者: MAYHEM-Lab 项目源码 文件源码
def _initial_farthest_traversal(self, data, seed=None):
        """ Find the initial set of cluster centers using Farthest Traversal strategy """
        # Pick first at random
        np.random.seed(seed)
        centers = data[np.random.randint(low=0, high=data.shape[0], size=1)]
        for _ in range(self.n_clusters - 1):
            dist = cdist(data, centers)
            dist = dist.sum(axis=1)
            assert dist.shape[0] == data.shape[0]  # making sure that axis=1 is correct
            # point with max. dist from all centers becomes a new center
            centers = np.append(centers, [data[np.argmax(dist)]], axis=0)
        return centers
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号