EasyDeepLearn

How do you choose the distance metric for KNN?

medium

Answer

  • Euclidean is the default for continuous features that have been standardized.
  • Manhattan (L1) is more robust to outliers and often used with sparse or high-dimensional data.
  • Cosine distance for text / normalized feature vectors where direction matters more than magnitude.
  • Mahalanobis when features have different scales and correlations (uses the inverse covariance).
  • Hamming for binary/categorical features.
  • Domain-specific metrics (e.g., edit distance for strings) when relevant.
Check yourself — multiple choice
  • Euclidean is always best
  • Match the metric to the feature type: Euclidean/Manhattan for continuous, cosine for text, Hamming for binary
  • Distance metric never matters
  • Only cosine works for KNN

The right metric depends on feature type: Euclidean/Manhattan/cosine/Hamming/etc.

#knn#features

Practise Supervised Learning

215 interview questions in this topic.

Related questions