0
$\begingroup$

I need to be able to select first N most representative points from each cluster calculated by K-means. To do so, I am aiming to calulate the distance of each point to its own cluster center and take the ones with the smallest values. To do this, I have used the K-means transform function:

kmeans= KMeans(n_clusters=18,random_state=2, n_init = 50, max_iter=500)
clusterer= kmeans.fit(data)
distances= kmeans.transform(data)[:,0]

To validate the results, I have calculated the points closest to the cluster centers:

closest_org, _ = pairwise_distances_argmin_min(clusterer.cluster_centers_, data)

and the points that I have calculated as the closest ones are not the one that have a smallest distance. Could you please advise on the optimal and correct way to calculate get the N closest points from each cluster?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.