0

I read here how to show the number of clusters over $n$ columns.

I would like to know how to get in a table, the values of the clusters centers. Could someone help me with this?

Ethan
  • 1,633
  • 9
  • 24
  • 39

1 Answers1

0

sklearn.clusters.KMeans has an attribute cluster_centers_, which stores the array of cluster centers.

You can add them to the dataframe as new columns this way:

clusters = KMeans(n_clusters = n)
predict = clusters.fit_predict(data)
centers = pd.DataFrame(clusters.cluster_centers_[predict, :])
centers.index = data.index
data = pd.concat([data, centers], axis=1)