Every from-scratch k-means implementation works on the textbook example and breaks on real data the first time a cluster loses every point it had. The mean of zero points is nan, and from that iteration on, everything downstream is nan too.
Write kmeans(X, k, seed, max_iters=100) implementing Lloyd's algorithm:
k centroids by drawing k distinct rows of X without replacement, using np.random.default_rng(seed).max_iters iterations.You have read the opening. The rest is free with a Bezen account, and no card is needed.
Behind the sign-in