Back to questions
JuniorTheoryCommon
What does this program print?
import numpy as np
X = np.array([[0], [1], [3], [4], [11]])
centroids = np.array([[0.0], [5.0]])
dist = np.array([((X - c) ** 2).sum(axis=1) for c in centroids])
labels = dist.argmin(axis=0)
new = np.array([X[labels == j].mean(axis=0) for j in range(2)])
print(new[0, 0], new[1, 0])0.5 6.0
- Expecting
0.5 4.0: the centroid moves to the mean of its points3,4and11, which is6.0;4.0is their median. - Expecting the centroids to move only part of the way: one k-means step puts each centroid exactly at the mean of its points, there is no step size.
- Which centroid would the point
3join if the second centroid started at7.0instead of5.0? - What should the update step do if no point is assigned to a centroid?