Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 711
awest1 Avatar asked Apr 05 '15 18:04

awest1


People also ask

What is label in k-means clustering?

kmeans = KMeans(n_clusters = k) y_pred = kmeans.fit_predict(X) Each instance is assigned to one of the five clusters. It receives a label as the index of the cluster it gets assigned to. We can see these labels: y_pred.

How do you plot a cluster center in Python?

You can draw the points and the centers via matplotlib's scatter function. Colors can be assigned depending on the group calculated via kmeans . Here is an example (the kmeans function now also return the centroids). Here is an attempt to show the given target names together with the kmeans approximation.


1 Answers

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

So:

kmeans.cluster_centers_[0] = centroid of cluster 0
like image 199
Kirell Avatar answered Oct 11 '22 00:10

Kirell