The Curse of Dimensionality, Explained

After reading this you will know why distances stop being informative as dimensions pile up, be able to compute the concentration of pairwise distances by hand, and know when to reach for feature selection or dimensionality reduction before running a distance-based method.

What the curse of dimensionality is

Distance is the workhorse of many machine-learning methods. k-nearest-neighbors, k-means, and kernel methods all rank points by how close they sit. In two or three dimensions your intuition about "close" and "far" holds up. In hundreds of dimensions it breaks in a specific, measurable way: the distances between points crowd together into a narrow band, so the nearest point and the farthest point end up almost the same distance away.

Here is the hook. Sample 500 points uniformly at random inside the unit cube. In one dimension the closest pair might be 0.002 apart and the farthest pair almost 1.0: a ratio near 500. Push that same experiment to 500 dimensions and every pairwise distance lands close to \sqrt{500/6} \approx 9.13, with the nearest and farthest neighbors differing by only a few percent. The ratio of farthest to nearest slides toward 1. When that happens, "the nearest neighbor" is barely nearer than anything else, and a method that trusts that ranking loses its grip.

Why volume runs to the shell

The clearest way to feel the curse is to track where volume lives. Take the unit cube in d dimensions and shrink each side to 90% of its length, centered. That inner cube holds a fraction 0.9^d of the total volume.

V_{\text{inner}} = 0.9^{\,d}

Here d is the number of dimensions and 0.9 is the side length of the inner cube as a fraction of the outer cube. In one dimension the inner interval keeps 90% of the length. At d = 10 it keeps 0.349. At d = 50 it keeps 0.00515, under 0.6%. At d = 100 it keeps 0.0000266. Almost all the volume has migrated into a thin shell within 5% of the boundary.

The same logic empties any center ball. A random point in the cube is overwhelmingly likely to sit near a face or corner, not near the middle. "Typical" points are all out at the edges, and the edges are far from the center but similar in distance to each other.

This is one face of a general result called concentration of measure. For a large class of distributions, a well-behaved function of many independent coordinates (like a distance) stays very close to its mean with high probability. The cube is just an easy case you can compute by hand.

The formula for distance concentration

Take two independent points drawn uniformly in the d-dimensional unit cube. Their squared Euclidean distance is a sum of d independent per-axis terms:

D^2 = \sum_{i=1}^{d} (X_i - Y_i)^2

Each X_i and Y_i is uniform on [0,1], so each gap X_i - Y_i lives on [-1,1]. For one axis, E[(X_i - Y_i)^2] = 1/6. Because the axes are independent, the expected squared distance grows linearly:

E[D^2] = \frac{d}{6}, \qquad E[D] \approx \sqrt{\frac{d}{6}}

The mean distance grows like \sqrt{d}. The variance of D^2 also grows linearly in d, so the standard deviation of D stays bounded (it approaches a constant near 0.246). Divide a bounded spread by a mean that grows like \sqrt{d} and the relative spread shrinks:

\frac{\text{sd}(D)}{E[D]} \sim \frac{1}{\sqrt{d}}

That single ratio is the curse in one line. At d = 4 the relative spread is about 0.30. At d = 100 it is about 0.060. At d = 400 it is about 0.030. The distances have collapsed toward a common value. Toggle the √d normalization in the tool and the histogram freezes in place: dividing every distance by \sqrt{d} cancels the growing mean and reveals that the underlying shape only gets narrower, never wider.

A worked example you can reproduce

The demo button samples 500 points uniformly in the unit cube using the field defaults. Walk the numbers for a few dimension settings and compare against the readouts.

Tracking the mean, spread, and neighbor ratio

  1. At d = 2: E[D] \approx \sqrt{2/6} = 0.577. The spread relative to the mean is roughly 1/\sqrt{2} \approx 0.71 times the base ratio, so distances range widely, from near 0 to about 1.3. The farthest-to-nearest ratio over 500 points is large, often 20 or more.
  2. At d = 25: E[D] \approx \sqrt{25/6} = 2.04. Relative spread is about 1/\sqrt{25} = 0.20 scaled by the shape constant, so most distances land between 1.6 and 2.5. The neighbor ratio has fallen to roughly 2 to 3.
  3. At d = 100: E[D] \approx \sqrt{100/6} = 4.08. Relative spread near 0.060 means almost every distance sits between 3.8 and 4.4. The neighbor ratio is now close to 1.3.
  4. At d = 500: E[D] \approx \sqrt{500/6} = 9.13, and distances cluster within a few percent of that. Nearest and farthest are nearly equidistant.

Small sampling noise means your live readout will not match to the last digit, but the trend is exact: the mean rises like \sqrt{d} and the ratio falls toward 1.

The expected distance between two random points climbs steadily with dimension, following sqrt(d/6).
The ratio of standard deviation to mean falls off as 1/sqrt(d), so distances concentrate into an ever-narrower band.

Without JavaScript, use the two charts above: as d rises from 1 to 500 the mean distance grows like \sqrt{d/6} while the relative spread falls like 1/\sqrt{d}, so the histogram of pairwise distances narrows toward a single value.

Why k-NN accuracy decays when you add noise features

The second panel of the tool makes the practical cost concrete. Two classes are separated cleanly in only 2 informative dimensions. Then you bolt on noise dimensions that carry no signal. Every noise axis adds a random term of size about 1/6 to the squared distance. The 2 informative axes contribute a fixed amount; the noise contributes a growing amount that swamps it.

Think of it as signal-to-noise inside the distance. With d_{\text{noise}} pure-noise axes added to 2 informative ones, the fraction of the squared distance that comes from signal is roughly:

\text{signal share} \approx \frac{2}{2 + d_{\text{noise}}}

At d_{\text{noise}} = 0 the signal share is 1.0 and k-NN separates the classes cleanly. At d_{\text{noise}} = 8 the share is 2/10 = 0.2. At d_{\text{noise}} = 48 it is 2/50 = 0.04. The two nearest neighbors of a query point are increasingly chosen by noise, so their labels are close to a coin flip and accuracy drifts toward the base rate of 50%.

Signal share and typical two-class k-NN accuracy as noise dimensions are added to 2 informative ones
Noise dimsTotal dimsSignal shareTypical k-NN accuracy
021.0000.97
240.5000.90
8100.2000.78
18200.1000.68
48500.0400.58
981000.0200.53

The accuracy column is representative rather than exact; it depends on the class gap and the value of k. The direction is the point: adding features that carry no signal makes a distance-based classifier worse, not neutral.

More features are not free. Every irrelevant column you feed a distance-based model adds noise to every distance computation. If you cannot justify a feature, dropping it often raises accuracy.

When the curse bites and when it does not

The curse is a statement about methods that rely on raw distances or volumes in the full input space. It bites hardest on:

  • k-nearest-neighbors and radius queries, where ranking by distance is the whole algorithm;
  • k-means and other centroid methods, where cluster assignment uses distance;
  • kernel and RBF methods with a fixed bandwidth, since a single scale cannot fit distances that all look the same.

It bites far less when the data does not actually fill the high-dimensional cube. Real data often lies on a low-dimensional manifold: images of faces vary in far fewer directions than the pixel count suggests. Tree-based models (random forests, gradient boosting) split one feature at a time and ignore irrelevant columns fairly well. Linear models with regularization can down-weight noise features directly. If your features are informative and your model does not compute global distances, adding dimensions is not automatically fatal.

Common mistakes

Three errors show up again and again.

Trusting Euclidean distance in raw high-dimensional space
When the farthest-to-nearest ratio is near 1.1, "nearest" is almost meaningless. Reduce dimensions first, or use a distance that weights informative axes.
Adding features because you have them
A feature with no signal still contributes about 1/6 to each squared distance in the unit cube. Ten such features can bury a two-dimensional signal, as the table above shows.
Skipping feature scaling
Concentration assumes comparable per-axis scales. One axis measured in thousands will dominate the distance regardless of dimension, which is a different failure. Scale first, then reason about dimension. The Feature Scaling Demo shows how much scaling alone changes distance-based results.

Related tools

Once you reduce or select features, the next questions are about model behavior. The Bias–Variance Decomposition shows why extra noise features raise variance. The Cross-Validation Visualizer gives you an honest estimate of how much accuracy you lost or gained by changing the feature set. If your reduced model outputs probabilities, check them with the Calibration & Reliability Diagram, and pick an operating point with the ROC & Threshold Explorer. For reasoning about how evidence sharpens an estimate as data accumulates, see the Bayesian Updating Visualizer.

Frequently asked questions

Does the curse of dimensionality mean you should never use many features?

No. It means you should not feed many uninformative features to a method that ranks points by distance. Informative features help. The problem is noise dimensions that dilute the distance, as the 2/(2 + d_{\text{noise}}) signal share makes precise.

Why does dividing every distance by the square root of d "freeze" the histogram?

The mean distance grows like \sqrt{d/6}, so dividing by \sqrt{d} removes that growth and leaves the center near the constant \sqrt{1/6} \approx 0.408. What remains is the shape, which keeps narrowing because the relative spread still falls like 1/\sqrt{d}.

How many dimensions is "high"?

There is no hard threshold, but the numbers speak. By d = 10 the inner-cube volume is already down to 0.349 and the neighbor ratio has dropped noticeably. By d = 50 under 0.6% of volume remains in the inner cube. Watch the readouts rather than a magic number.

What should you do about it in practice?

Select features by relevance, or reduce dimension with a method like PCA before running k-NN or k-means. Scale features to comparable ranges first. Prefer models that ignore irrelevant features (regularized linear models, tree ensembles) when the feature count is large and you cannot prune it.

Do these exact formulas apply to real data?

The clean formulas (E[D] = \sqrt{d/6}, volume 0.9^d) assume points spread uniformly and independently in a cube, which real data rarely does. Real data often occupies a lower-dimensional manifold, so the effective dimension is smaller than the raw feature count. The direction of the effect holds; the exact numbers are the worst case.