Value at KMeans.cluster_centers_ in sklearn KMeans

15,586

Solution 1

closest, _ = pairwise_distances_argmin_min(KMeans.cluster_centers_, X)

The array closest will contain the index of the point in X that is closest to each centroid.

Let's say the closest gave output as array([0,8,5]) for the three clusters. So X[0] is the closest point in X to centroid 0, and X[8] is the closest to centroid 1 and so on.

Source: https://codedump.io/share/XiME3OAGY5Tm/1/get-nearest-point-to-centroid-scikit-learn

Solution 2

The cluster centre value is the value of the centroid. At the end of k-means clustering, you'll have three individual clusters and three centroids, with each centroid being located at the centre of each cluster. The centroid doesn't necessarily have to coincide with an existing data point.

Share:
15,586
Katherine
Author by

Katherine

Updated on June 12, 2022

Comments

  • Katherine
    Katherine almost 2 years

    On doing K means fit on some vectors with 3 clusters, I was able to get the labels for the input data. KMeans.cluster_centers_ returns the coordinates of the centers and so shouldn't there be some vector corresponding to that? How can I find the value at the centroid of these clusters?