K-Means: Assign & Update

medium
Unit 8 · Clustering0/3 to milestone

Implement one iteration of Lloyd's algorithm.

  1. assign(X, centroids) — return an integer array of length n with the index of the nearest centroid (Euclidean) for each point.
  2. update(X, labels, k) — return a (k, d) array of the mean of each cluster's points. If a cluster is empty, its centroid should be all zeros.
  3. kmeans(X, init_centroids, iters) — run iters iterations and return the final centroids.
#clustering#unsupervised2 visible + 2 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
K-Means: Assign & Update · TechGradify