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.If an update step leaves a cluster with zero points assigned, its centroid does not become nan. Reassign it to the point in X currently farthest from its own assigned centroid — the single point contributing the most to the total squared distance — breaking ties by the smallest index. Give that reassigned centroid the point that was picked for it, so the next assignment step is not immediately contradicted.
Return (labels, centroids): labels an (n,) int array with values in [0, k), centroids a (k, d) float array.
Build the architecture on a canvas: place the components, configure them, connect them into a data flow, and write a short reason for each one. The AI reviewer grades your design against a rubric written specifically for this problem.
Minimum 5 components · needs a wide desktop screen