0
$\begingroup$

I have used the KMeans algorithm to create an engine that can guess the cluster that a particular set of input data will fall into.

Can I use it to guess the 2nd closest cluster, 3rd closest, and so on?

Currently, I am using the sklearn.cluster.KMeans library if that's any help - it doesn't seem like the API provides this functionality already.

$\endgroup$
1
  • 1
    $\begingroup$ @Romain Reboulleau is correct. KMeans is based on Euclidean distances, so even though Sklearn doesn't provide this functionality out of the box, ranking the clusters per euclidean distance will do the trick $\endgroup$ – Valentin Calomme Dec 2 '19 at 12:56
2
$\begingroup$

You could simply compute the distance to each cluster center provided in the cluster_centers_ attribute (once the KMeans instance is fitted). The predict method actually does that for the closest cluster center.

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.