Full k-means touches every point each iteration. Mini-batch k-means updates centroids from small random batches with a per-centroid learning rate.
Implement minibatch_kmeans(X, init_centroids, batch=32, iters=100, seed=0):
n_c of points ever assigned to each centroid (start at 0)batch row indices with rng.integers(0, n, batch) (one np.random.default_rng(seed)), assign each sampled point to its nearest centroid, then for each sampled point in order: n_c += 1, c += (x - c) / n_cReturn the final centroids (copy the initial ones, don't modify the input).