Foundations

The Curse of Dimensionality and Why Distances Stop Helping

See why space empties out as features are added, why nearest and farthest points look alike, and what to do about it.

Key takeaways

  • The volume of space grows exponentially with dimension, so a fixed number of examples covers it ever more thinly.
  • To capture a small fraction of uniform data, a neighborhood in high dimensions must span most of each feature's range.
  • With many independent, comparably scaled features, pairwise distances concentrate around a common value.
  • Irrelevant features add noise to distances and can drown the informative ones.
  • Real data often have far lower intrinsic dimension than their feature count, which is why learning still works.

The curse of dimensionality is the collection of problems that appear as the number of features d grows: data become sparse, neighborhoods stop being local, and the distance to your nearest example can be nearly as large as the distance to your farthest one. Methods that rely on nearby points suffer most.

The phrase is usually credited to Richard Bellman, who used it in work on dynamic programming in the middle of the twentieth century.

Space empties out

Cut each feature's range into 10 intervals. With one feature you have 10 cells. With two, 100. With d, you have 10ᵈ. At d = 10 that is ten billion cells, so a data set of a million examples leaves almost all of them empty.

Any method that estimates something cell by cell, or neighborhood by neighborhood, runs short of examples. To keep the same density, the number of examples would have to grow exponentially with d.

Example: side length needed to capture 1% of uniform data in a unit cube
1 feature 0.01share of each axis 2 features 0.1share of each axis 10 features 0.63share of each axis 100 features 0.96share of each axis 1 feature 0.01share of each axis 2 features 0.1share of each axis 10 features 0.63share of each axis 100 features 0.96share of each axis

Hypothetical example: the numbers are made up to show the method, not a quote or an average.

Neighborhoods stop being local

Suppose examples are spread uniformly in a cube with sides of length 1, and you want a small sub-cube around a query that holds a fraction r of them. Its side length must be r^(1/d).

Features d Side needed for r = 0.01
1 0.01
2 0.10
10 about 0.63
100 about 0.955

In 100 dimensions, a "neighborhood" with 1% of the data stretches across more than 95% of the range of every feature. Averaging labels over it is close to averaging over everything.

Volume moves to the edges

Take a ball of radius 1 and ask how much of its volume lies within 0.01 of the surface. The inner ball has volume 0.99ᵈ times the whole, so the outer shell holds 1 − 0.99ᵈ.

d = 10:    1 − 0.99¹⁰   ≈ 0.096
d = 100:   1 − 0.99¹⁰⁰  ≈ 0.634
d = 1000:  1 − 0.99¹⁰⁰⁰ ≈ 0.99996

In high dimensions, nearly all of a ball is skin. Similarly, a ball inscribed in a cube fills about 79% of it in 2 dimensions, about 52% in 3, and only about 0.25% in 10. Most of the cube sits out in its many corners.

Your two-dimensional pictures are poor guides here. Typical points are not near the middle of anything.

Distances concentrate

Draw two points whose coordinates are independent and uniform on [0, 1]. Their squared Euclidean distance is a sum of d independent terms (uⱼ − vⱼ)², each with mean 1/6 and variance 7/180.

mean of squared distance        = d/6
standard deviation              = √(7d/180)
relative spread (sd ÷ mean)     ≈ 1.18/√d

The relative spread is about 0.84 for d = 2, 0.12 for d = 100 and 0.012 for d = 10,000. The distances still grow, but compared with their typical size they become nearly identical. The gap between your closest and tenth-closest neighbor may then be mostly chance.

You can watch this happen:

import numpy as np

rng = np.random.default_rng(0)
for d in [2, 10, 100, 1000]:
    data = rng.uniform(size=(2000, d))     # shape (2000, d)
    query = rng.uniform(size=d)
    dist = np.linalg.norm(data - query, axis=1)
    print(d, round(dist.min() / dist.max(), 3))

The ratio of nearest to farthest distance climbs toward 1 as d increases.

Sampling and integration feel it too

The curse is not limited to prediction. Suppose you estimate the share of the cube that falls inside the inscribed ball by throwing random points. In 2 dimensions, most points land inside. In 10 dimensions only about 1 in 400 does, and in 20 dimensions you could throw millions and see none or almost none.

Any method that samples blindly and hopes to hit a small region has this problem. It affects rejection sampling, naive importance sampling, random exploration in large state spaces and exhaustive searches over many hyperparameters.

Plain Monte Carlo averaging is an interesting exception. Its standard error falls like 1/√m with m samples, with no explicit dependence on dimension. The difficulty moves into the variance: if the quantity is dominated by a rare region, the variance relative to the mean can be enormous.

Optimization has a related story. A grid with 10 values for each of 6 settings already has a million combinations. Random search often does better with the same budget, because it tries many distinct values of whichever few settings turn out to matter.

Which methods suffer

Method Why dimension hurts, or hurts less
k-nearest neighbors Depends directly on meaningful distances
Kernel density estimation Needs exponentially more data for the same precision
Distance-based clustering Cluster contrast fades when many features are noise
Grid search over inputs or settings Number of grid points grows exponentially
Linear models with regularization Assume simple global structure, so cope better
Tree ensembles Select features when splitting, which filters some noise

None is immune. A linear model with many more features than examples can fit random labels perfectly, which is why regularization matters there. Search problems feel the curse too: approximate nearest neighbor search exists partly because exact index structures lose their advantage as dimension rises.

Irrelevant features do the damage

Imagine two features that separate your classes well. Add 200 columns of random noise on the same scale. The distance between two examples is now dominated by the noise columns, and a nearest neighbor classifier drifts toward guessing.

What counts is how many independent directions of variation reach your distance, and how many of them relate to the target. Adding a duplicate of a good feature does not create new independent noise, though it does change the weighting.

A related effect is hubness: in high-dimensional data, a few points can show up among the nearest neighbors of a great many others, which distorts neighbor-based predictions and retrieval.

How much one signal is diluted

A small calculation shows the dilution. Take two classes that differ only in the first feature, with the class means 2 units apart, and give every feature independent noise with standard deviation 1.

For two examples from the same class, each coordinate difference has variance 2, so the expected squared distance across d features is 2d. For two examples from different classes, the first feature adds 2² = 4, giving 2d + 4.

d = 2:     same class 4,     different class 8      ratio 2.00
d = 20:    same class 40,    different class 44     ratio 1.10
d = 200:   same class 400,   different class 404    ratio 1.01

The signal contributes the same 4 units throughout. The background grows with every noise feature, and the random fluctuation in the squared distance grows too, roughly like √d. With 200 features, an extra 4 units is small compared with that fluctuation, so neighbors from the wrong class slip in often. Selecting or weighting features restores the contrast, provided you can find the informative ones without peeking at test labels.

Why learning still works

Images, sound and text have thousands of dimensions, and models handle them. Several reasons help.

  1. Real data concentrate near lower-dimensional structure. Pixels in a photo are strongly dependent. This idea is the manifold hypothesis.
  2. The target often depends on a few directions or on smooth combinations of features.
  3. Models build in assumptions, such as locality in convolutions, that shrink the search.
  4. Learned embeddings, vectors trained so that related items lie close together, give distances that mean something even with hundreds of dimensions.

The independence assumption in the distance calculation is the key. When coordinates are strongly correlated, distances need not concentrate in the same way.

What to do in your own project

  1. Check whether neighbors make sense by looking at them. Pick several queries and read the retrieved examples.
  2. Compare the nearest-neighbor distance with the typical pairwise distance. A ratio near 1 is a warning.
  3. Remove or down-weight uninformative features, selecting them inside each training fold.
  4. Scale features so that units do not decide importance.
  5. Reduce dimension with principal component analysis or a learned representation, remembering that high variance is not the same as relevance.
  6. Try cosine distance for embeddings or text vectors, and validate the choice.
  7. Prefer methods whose assumptions match the data when examples are scarce.

Common questions

How many features is too many?

There is no fixed count. It depends on the number of examples, the correlation among features, the share that carries signal and the method. Test by adding and removing feature groups.

Does collecting more data fix it?

It helps, but under worst-case assumptions the required amount grows exponentially with intrinsic dimension. Better features and stronger assumptions usually buy more.

Is high dimension always bad?

No. Mapping data into many dimensions can make classes easier to separate with a flat boundary. The trouble is with relying on raw proximity when the extra directions carry little signal.

Concentration of measure, the same effect that blurs distances, can even help. Random projections use it to compress a finite set of points into fewer dimensions while keeping pairwise distances approximately intact with high probability. Preserving distances does not make them informative, though: if they were dominated by noise before, they still are.

Should I worry if my model uses only a few hundred features?

Check rather than guess. A few hundred strongly related features may behave like a handful of dimensions, while a few dozen independent noisy ones can already spoil a neighbor search on a small data set.

Written for 4MachineLearning with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 42 articles in Foundations →

Latest news on this topic