5 hidden checks

Implement the two steps of k-means and a PCA projection.

  • assign(X, C): for data X (n, d) and centres C (k, d), return an integer array of length n with the index of each point's nearest centre.
  • update(X, labels, k): return a (k, d) array whose row j is the mean of the points labelled j. (You may assume every cluster has at least one point.)
  • pca(X, n): centre X, compute its SVD, and return (components, Z) where components has shape (n, d) (the top n directions as rows) and Z = X_centred @ components.T has shape (len(X), n).
checks
  • assign picks the nearest centrenot run
  • update moves centres to the meansnot run
  • k-means on iris converges to sensible clustersnot run
  • pca returns orthonormal top directionsnot run
  • pca projections have decreasing variance and match the SVDnot run
python sleeps until you press run

Press Run & check. Your code runs first, then the hidden checks on the left.