0
$\begingroup$

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

$\endgroup$
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$

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.