Suppose I fit sklearn.cluster.KMeans with the data and get the following:
kmeans = KMeans(n_clusters=3, random_state=0).fit(X)
kmeans.cluster_centers_ = array([[-0.9876 , -0.534, 0.342],
[ 1.243, 1.235, 0.887 ],
[ 0.242, 0.243, 0.02348]])
kmeans.labels_ = [2, 2, 2, 1, 0, 2, 2, 1, 1, 1, 0, 0, 2, 0, 1]
Does this mean that, all elements with labels 2
belong to the first center [-0.9876 , -0.534, 0.342]
, all elements with labels 1
belong to the the second center [ 1.243, 1.235, 0.887 ]
and all elements with labels 0
belong to the third center [ 0.242, 0.243, 0.02348]
?
In other words, the first label to arrive in the list belongs to the first center in the list of centers, the next element in the list of labels that is different from the first belongs to the second center, and so on. Is this how centers and labels are ordered?km
CodePudding user response:
The labels are the indices of the rows in kmeans.cluster_centers_
: all elements with labels 2
belong to the center kmeans.cluster_centers_[2]
.
The ordering of the rows is arbitrary.