Distance metrics
Distance metrics are different formulas used by KNN/ANN to measure distance and select the nearest neighbors. The compatible ones vary depending on the backend.
Use the table below to select a distance metric(s) supported by the backend being used:
Legend
- β Native support
- π Fallback to exact
sklearnKNN - β Not supported
| Metric | Why it matters for DES | KNN (exact) | FAISS flat/HNSW | FAISS IVF | Annoy | HNSW (hnswlib) | HNSW (nmslib) |
|---|---|---|---|---|---|---|---|
euclidean |
Standard L2 norm; best default for continuous feature spaces. Defines spherical local regions for selecting competent classifiers. | β | β | β | β | β | β |
manhattan |
L1 norm; robust to outliers and often preferable in highβdimensional feature spaces (mitigates the curse of dimensionality for DES). | β | β | π | β | β | β |
chebyshev |
Lβ norm; focuses on the worstβcase feature deviation. Useful when a single dominant feature dictates similarity (e.g., bounded grids). | β | β | π | β | β | β |
minkowski |
Generalises L1/L2 via p; lets you tune the shape of the local neighbourhood between Manhattan and Euclidean. |
β | β | π | β | β | β |
cosine |
Angle between vectors, ignoring magnitude. Ideal for normalised embeddings (deep features, TFβIDF) where direction, not scale, matters for classifier competence. | β | β | β | β | β | β |
dot |
Inner product (not a metric). Used for maxβinnerβproduct search (e.g., recommender systems). Generally not recommended for standard DES unless you specifically need relevanceβbased ranking. |
β | β | β | β | β | β |
canberra |
Weighted L1 that emphasises relative changes; sensitive to values near zero. Useful for sparse count data or features where zeros are meaningful. | β | β | π | β | β | β |
braycurtis |
Normalised L1 bounded to [0,1]; common for compositional or ecological data (e.g., abundance vectors). | β | β | π | β | β | β |
jensenshannon |
Symmetric KL divergence; requires nonβnegative inputs. Ideal for measuring similarity between classifier output probability distributions or bagβofβword features. |
β | β | π | β | β | β |
correlation |
Pearson correlation distance (1βΟ). Good for timeβseries or features with linear trends β helps select classifiers that generalise across similar patterns. |
β | π | π | β | β | β |
hamming |
Fraction of differing binary/categorical components. Directly applicable to binary feature spaces or binarised classifier predictions. | β | π | π | β | β | β |
| --- |