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
评论列表
文章目录