abw
abw

Reputation: 85

Labels for cluster centers in Python sklearn

When utilizing the sklearn class sklearn.cluster for K-means clustering, a fitted k-means object has 3 attributes, including a numpy array of cluster centers (centers x features) named cluster_centers_. However, these centers don't have an attached label.

My question is: are the centers (rows) in cluster_centers_ ordered by the label value? That is, does row 1 correspond to the center for the cluster labeled 1? Or are they placed in the array randomly? A pointer to any documentation would be more than sufficient.

Thanks.

Upvotes: 8

Views: 5777

Answers (1)

Kirell
Kirell

Reputation: 9798

I couldn't find the documentation but yes it is ordered by cluster.

So:

kmeans.cluster_centers_[0] = centroid of cluster 0

Upvotes: 7

Related Questions