Search code examples
python-3.xmachine-learningcluster-analysisk-means

How to get features/attributes of a data point if its distance from the cluster's center is known?


I have a DataFrame X with columns A, B and C. I applied kMeans clustering with n_clusters=4 and got euclidean distance of 10 nearest data points from each cluster's center. Example, for ith cluster, I did this:-

#getting 10 nearest points from ith cluster center
print(np.sort(kmeans.transform(X)[:, i])[: 10])
#output:-
array([0.06096257, 0.07785726, 0.09155965, 0.09301038, 0.09741242,
   0.1016601 , 0.10242911, 0.10314227, 0.10775149, 0.10895064])

Now, I want to get features A, B and C for these 10 data points. How to pull this off?


Solution

  • Use argsort if you want to get the indexes of the smallest values.

    Mapping distances to points is complicated.