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?
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?
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)
KMeans
class stores the cluster centers in thecluster_centers_
attribute, which returns an array of shape(n_clusters, n_features)
(see also the documentation). $\endgroup$