0
$\begingroup$

In k-means or kNN, we use euclidean distance to calculate the distance between nearest neighbours. Why not manhattan distance ?

$\endgroup$

1 Answer 1

1
$\begingroup$

No, KNN is generic and you can use any valid metric you want. For example, cosine distance is another metric that is used frequently. Here is an implementation in scikit-learn where you can choose among several distance options. You can also define your own metric to use.

K-means is slightly different. It really uses Euclidean distance, and it becomes a harder problem for generic metrics. However, k-medians is a variation of k-means with L1 distance. it has variations such as k-medians (using L1 distance). k-medoids is another generalization of this algorithm where the cluster center is chosen among the data points and you can use any metric with it.

$\endgroup$
1
  • $\begingroup$ There is also the spherical k-means, based on cosine distance $\endgroup$
    – MysteryGuy
    Commented Dec 3 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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