Classical machine learning
Distance, Scaling, and the Curse of Dimensionality
Compare distance metrics, scaling choices, mixed-data encodings, high-dimensional concentration, and metric audits for local models.
By the end you can
- Compare Euclidean, Manhattan, cosine, and covariance-adjusted distances
- Explain why scaling changes the semantic weight of features
- Diagnose distance concentration and unstable neighborhoods in high dimensions
- Audit a metric through pair inspection, decomposition, perturbation, and downstream tests
Example
Distance can be numerically valid and semantically absurd
A metric returns a number. Almost any pair of encoded rows will produce one. That number is useful only when feature differences correspond to meaningful similarity.
- Age in years plus income in euros: unscaled Euclidean distance is dominated by income units.
- Postal codes treated as numbers: neighboring codes may be geographically unrelated, while distant codes may be adjacent.
- One-hot categories: two rare categories are equally distant even if domain knowledge says one pair is much more similar.
- Sparse text vectors: Euclidean length can reflect document size more than topic, while cosine focuses on direction.
- Mixed medical data: binary findings, lab values, and missingness indicators may require different weights and semantics.
Comparison
Common metrics encode different notions of difference
No metric is universally neutral, and the claim has been tested rather than asserted.
The exponent in the L_k norm is a choice, and it changes what the distance means. A 2001 paper by Aggarwal and two colleagues examined exactly that. They found “that the problem of meaningfulness in high dimensionality is sensitive to the value of k”, and drew a recommendation from it: “the Manhattan distance metric (L1 norm) is consistently more preferable than the Euclidean distance metric (L2 norm) for high dimensional data mining applications”. Pushing k below 1 helped further. Those fractional distance metrics are no longer metrics in the strict sense, and the paper reports that they “can significantly improve the effectiveness of standard clustering algorithms such as the k-means algorithm”.
The size of that improvement sits in their k-means experiment: six clusters of 10,000 points each, at d = 20. “The results of our experiments show that the fractional distance metrics provides a much higher classification rate which is about 99% for the fractional distance metric with f = 0.3 versus 89% for the Euclidean metric”. A different exponent, and nothing else, moved the classification rate from 89% to about 99%.
Two later groups then tested the recommendation and did not confirm it as a general rule. François and colleagues at the Université catholique de Louvain proved in 2007 that “fractional norms are not always less concentrated than higher order norms”. Mirkes and two colleagues ran the comparison again in 2020, in a paper whose title says that fractional norms and quasinorms do not help to overcome the curse of dimensionality. They found that “the difference of the performance of kNN based on lp for p=2, 1, and 0.5 is statistically insignificant”. Euclidean distance is a default rather than a neutral choice. L1 is a hypothesis to test on your own data, not a repair to adopt on someone else's synthetic workload.
How much the choice can be worth is visible on a fixed benchmark. MNIST is 60,000 training and 10,000 test images. Hold the classifier family at k-nearest-neighbour and change only the distance. The benchmark table published by Yann LeCun and Corinna Cortes lists Euclidean L2 at 5.0% test error for LeCun et al. 1998. On identical unprocessed data it lists L2 at 3.09% against L3 at 2.83% (Kenneth Wilder). Tangent distance reaches 1.1%. The image distortion model reaches 0.54%, and its P2DHMDM variant 0.52%. From 5.0% to 0.52% is roughly a factor of ten, moved by the distance function alone.
Read the column carefully, though. The pixels are not held constant all the way down it. Only the 3.09%-versus-2.83% pair is a strictly like-for-like swap on unprocessed data. The lowest rows are matching procedures rather than formulas. Keysers describes his this way: “The distance as determined by the best match between two images is then used within a 3-nearest-neighbor classifier.”
Euclidean, Manhattan, cosine and Mahalanobis are four points in that space of choices: straight-line distance after encoding and scaling; coordinate-wise absolute difference; angle rather than magnitude; and covariance-adjusted distance that needs a stable covariance estimate and a reference distribution to be adjusted against.
Euclidean
Straight-line distance after encoding and scaling.
- Sensitive to feature units
- Emphasizes large coordinate differences
- Works naturally with spherical geometry
- Degrades in high dimensions
Manhattan
Sum of absolute coordinate differences.
- Coordinate-wise contribution
- Less dominated by one squared gap
- Still scale-sensitive
- Can suit sparse grid-like variation
Cosine
Angle between vectors rather than absolute magnitude.
- Common for sparse counts or embeddings
- Ignores overall vector length
- Undefined for zero vectors without handling
- Similarity may not match downstream outcomes
Mahalanobis
Distance adjusted by covariance structure.
- Accounts for correlated directions
- Requires stable covariance estimation
- Can be fragile in wide data
- Depends on the reference distribution
Visual
Why neighborhoods lose contrast in high dimensions
As irrelevant dimensions accumulate, distances often become less discriminative.
Add enough dimensions and the nearest point stops being different from the farthest one. Beyer and three colleagues at the University of Wisconsin–Madison proved that in 1999, and then measured where it bites. Their abstract states the result: “We show that under a broad set of conditions (much broader than independent and identically distributed dimensions), as dimensionality increases, the distance to the nearest data point approaches the distance to the farthest data point.” The practical number is smaller than people expect. The effect “can occur for as few as 10-15 dimensions”, and in their synthetic experiments the distinction blurs at 15. On the workloads they examined, “linear scan would outperform the techniques being proposed on the workloads studied in high (10-15) dimensionality”. They are careful about the boundary of the claim. They also “identify special workloads for which the concept of nearest neighbor continues to be meaningful in high dimensionality”.
The result did not stay one paper's claim. François and colleagues re-derived it independently in 2007 and established that the concentration “is indeed an intrinsic property of the distances and not an artifact from a finite sample”. It tracks intrinsic dimension rather than embedding dimension. A column count is therefore not by itself a diagnosis.
Flattened distances are only half of the damage. In high dimensions a few points become everyone's neighbour. Radovanović and two colleagues measured that in 2010, on a broad evidence base: “In all, we examined 50 real data sets from well known sources, belonging to three categories: UCI multidimensional data, gene expression microarray data, and textual data in the bag-of-words representation”. Across those sets, the Spearman correlation between dimensionality d and the skewness of 10-occurrences is 0.62. As d rises, a shrinking handful of rows captures the 10-nearest-neighbour lists of everything else.
Engineers are still building around the effect. A 2025 AAAI paper turns hub detection into a sampling problem, finding hubs from 10% of the points under dot-product, L1, L2 and dynamic-time-warping distances. Its motive is stated plainly: “The hubs' effects, called the hubness phenomenon, degrade the performance of kNN based models in high dimensions”.
So the layers are: useful signal dimensions, where proximity relates to the target; noisy dimensions that add distance without adding relevance; concentration, where nearest and farthest converge; and unstable neighborhoods, which now has a name and a number rather than a warning. The test is empirical. Measure the gap between nearest and farthest distance on your own queries, and count how often the same rows appear in everyone else's neighbour lists.
- 01
Useful signal dimensions
Coordinates where proximity relates to the target.
- 02
Noisy dimensions
Independent variation that adds distance without adding relevance.
- 03
Distance concentration
Nearest and farthest distances become relatively similar.
- 04
Unstable neighborhoods
Small representation changes reorder the selected cases.
Scaling is a statement about relative importance
Standardization gives features comparable variance rather than comparable meaning. A one-standard-deviation change in blood pressure and a one-standard-deviation change in age become numerically similar even if their domain relevance differs.
Robust scaling, transformations, clipping, and domain weights can help, but each changes the neighborhood definition and must be fit within the training boundary. Note how specific a scaling convention has to be before it is reproducible. R's `daisy` does not say "scaled". It names the operation: each variable is “first standardized by dividing each entry by the range of the corresponding variable, after subtracting the minimum value; consequently the rescaled variable has range [0,1], exactly”. That is the level of detail a scaling decision needs to be written down at.
Mixed data needs a designed geometry
Numeric, binary, categorical, cyclic, ordinal, and set-valued fields do not share one natural subtraction rule. One-hot encoding plus Euclidean distance is a baseline, not a proof of meaningful similarity.
Sometimes separate candidate filters and within-group distances are clearer than one global metric.
One such designed geometry was written down in Biometrics in 1971, by J. C. Gower. His general coefficient distinguishes “Dichotomous, qualitative, and quantitative variates”, then scores each type by its own rule. “For qualitative characters we set sᵢⱼₖ = 1 if the two individuals i and j agree in the kth character and sᵢⱼₖ = 0 if they differ”. “For quantitative characters … we set sᵢⱼₖ = 1 − |xᵢ − xⱼ|/Rₖ. Here Rₖ is the range of character k and may be the total range in the population or the range in the sample.” A second quantity carries missing data: δᵢⱼₖ, “equal to 1 when character k can be compared for i and j, and 0 otherwise”. The similarity is then “the average score taken over all possible comparisons”. Absence enters the definition, instead of being imputed before it.
The aim was practical, and Gower said so: the coefficient “It is particularly suitable for including in computer programs because it can cope with a variety of different data-types without any reprogramming”. He records that it had been used in computer programs since 1960.
That aim is now checkable in shipping software rather than in a fifty-year-old sentence. R's `cluster` package implements the coefficient as `daisy(metric = "gower")` and reaches for it on its own. Its reference manual states that “The handling of nominal, ordinal, and (a)symmetric binary data is achieved by using the general dissimilarity coefficient of Gower (1971)”. Each variable is “first standardized by dividing each entry by the range of the corresponding variable, after subtracting the minimum value; consequently the rescaled variable has range [0,1], exactly”. And “missing values in a row of x are not included in the dissimilarities involving that row”. One function and one argument buy you per-type scoring, range standardisation, and missing values excluded from the comparisons they would have corrupted. That is a different default from imputing them and then reaching for Euclidean distance.
Steps
Audit a distance metric with real pairs
Aggregate accuracy alone can hide nonsensical neighborhoods. Select anchor cases that are common, rare, boundary, and operationally important. Read the nearest and farthest pairs with a domain expert. Decompose each distance to show which features drove it. Perturb one field and measure how neighbor order moves. Compare metrics, scalings and representations against each other. Then validate downstream, confirming that better semantic neighborhoods improve the actual task. The MNIST column above is what step five looks like when it is done properly: one benchmark, one classifier rule, the distance swapped, and the error rate read off each time.
1. Select anchor cases
Choose common, rare, boundary, and operationally important rows.
2. Read nearest and farthest pairs
Ask domain experts whether the ranking makes sense.
3. Decompose the distance
Show which features contribute most for each pair.
4. Perturb one field
Measure how a plausible change alters neighbor order.
5. Compare metrics
Test alternative scaling, weighting, or representations.
6. Validate downstream behavior
Confirm that better semantic neighborhoods improve the actual task.
Analogy
A travel time map instead of a ruler
A hospital chosen by straight-line distance ignores rivers, roads, and border crossings. A travel-time map defines closeness more usefully because it incorporates the structure that matters for the trip.
Roads change slowly, while learned feature spaces change with the data and may encode hidden biases. There may also be several legitimate notions of closeness for one product.
A good metric compresses domain structure into the differences that matter for the decision.
Key idea
Dimension reduction can improve distance and erase rare structure
Removing low-variance or weakly supervised directions can reduce noise, memory, and search cost. It can also discard a rare feature that defines the cases of greatest interest.
The reduction is worth measuring in both directions. Weinberger and Saul ran MNIST on 164 principal components out of 784 features and improved on Euclidean kNN. François and colleagues found that concentration tracks intrinsic rather than embedding dimension, which means dropping columns is not automatically dropping the problem. Validate transformations on rare-event, subgroup, and boundary slices, not only average neighbor quality.
A compact space is useful only if it preserves the distinctions the product must act on.
Metric learning moves the problem rather than removing it
Supervised metric learning or learned embeddings can pull same-label cases together and push others apart. The resulting geometry inherits label quality, sampling, objective choices, and protected-attribute proxies.
The gain is real and measurable in the model's own units. Weinberger and Saul held the kNN rule fixed and learned a Mahalanobis metric instead, and published the numbers in 2009. On the 20 Newsgroups data set: “The best result for LMMN on this data set improved significantly over kNN classification using Euclidean distances and PCA (with 14.98% versus 48.57% and 18.22% test error rates).” The misspelling “LMMN” is as printed in the paper. On MNIST — 70,000 inputs, 784 features reduced to 164, 60,000 training and 10,000 test examples — the test error moved from 2.12% with Euclidean kNN to 1.72% with LMNN. Hosseini and Hammer report the same benchmark at 164 dimensions in 2018: 97.57 accuracy for kNN, 98.28 for sp-lmnn, 98.31 for mp-lmnn.
What the learned geometry does not fix is who the threshold is fair to. NIST ran its Face Recognition Vendor Test Part 3 in December 2019: 18.27 million images of 8.49 million people, 189 algorithms from 99 developers. Across demographic groups, false-positive rates varied “by factors of 10 to beyond 100 times”. The Executive Summary is specific about the direction: “Using the higher quality Application photos, false positive rates are highest in West and East African and East Asian people, and lowest in Eastern European individuals.” Krishnapriya and four colleagues report the same class of effect on the MORPH data set: “For a fixed decision threshold, the African-American image cohort has a higher false match rate and a lower false non-match rate.” One embedding, one distance, one global cut-off — and an error rate that depends on who is being compared.
Inspect retrieval examples and failure slices even when the representation was learned end to end.
A learned distance is an optimized policy about similarity, not an objective fact.
Key takeaways
- A distance value is meaningful only when the representation turns coordinate differences into relevant similarity — on MNIST, with the k-nearest-neighbour rule held fixed, swapping the distance moves test error from 5.0% to 0.52%.
- Euclidean, Manhattan, cosine and Mahalanobis preserve different assumptions, and the L1-over-L2 recommendation from Aggarwal and colleagues (99% versus 89% on their d=20 k-means workload) was not confirmed as a general rule by François and colleagues in 2007 or by Mirkes and colleagues in 2020.
- Standardization equalizes variance scales but does not determine domain importance; a reproducible scaling rule has to be stated as precisely as `daisy`'s range standardisation onto [0,1].
- Irrelevant dimensions make nearest and farthest distances converge — Beyer and colleagues found it “can occur for as few as 10-15 dimensions”, and François and colleagues showed it is intrinsic to the distances rather than a finite-sample artifact.
- High dimensions also concentrate popularity: Radovanović and colleagues measured a Spearman correlation of 0.62 between dimensionality and the skewness of 10-occurrences across 50 real data sets, so a few hubs capture everyone's neighbour lists.
- Mixed data benefits from an explicitly designed geometry — Gower's 1971 coefficient, shipping today as `daisy(metric = "gower")` — and learned metrics need the same audits: Weinberger and Saul cut 20 Newsgroups error from 48.57% to 14.98%, while NIST found false-positive rates varying “by factors of 10 to beyond 100 times” across demographic groups at one threshold.