5 hidden checks
Implement the two steps of k-means and a PCA projection.
assign(X, C): for dataX(n, d)and centresC(k, d), return an integer array of lengthnwith the index of each point's nearest centre.update(X, labels, k): return a(k, d)array whose rowjis the mean of the points labelledj. (You may assume every cluster has at least one point.)pca(X, n): centreX, compute its SVD, and return(components, Z)wherecomponentshas shape(n, d)(the topndirections as rows) andZ = X_centred @ components.Thas shape(len(X), n).
- 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