Plain k-means picks starting centers uniformly at random, and bad luck can drop two starting centers into the same blob. The run then converges to a poor local optimum. k-means++ spreads the starting centers out: the first center is random, and each later center is chosen with probability proportional to its squared distance from the nearest center already picked. Far-away points are likelier, so new centers land in unexplored regions.
Implement kmeans_plus_plus_init(X, k, seed=0), which returns a (k, d) array whose rows are chosen points from X.
1 <= k <= n, otherwise raise ValueError.seed must give the same centers.X.Open one at a time. Each gives away a little more than the last.
Keep a list of chosen indices. Update a running d2 array with np.minimum after each new center.
rng.choice(n, p=d2 / d2.sum()) samples the next index. Guard against an all-zero d2 first.
No results yet
Run your code to check it against the examples, or submit to run every test.