Tutorials › Exam SRM - Statistics for Risk Modeling › The Curse of Dimensionality in KNN

Exam SRM · Nearest-Neighbor Learning · Tutorial 804 of 926

The Curse of Dimensionality in KNN

Learn how increasing predictor dimension concentrates distances, thins local neighborhoods, and can make KNN predictions depend on observations that are no longer truly local.

Intermediate 11 min read

What You'll Learn

  • Calculate the volume of a centered neighborhood in a unit hypercube.
  • Find the nearest-neighbor radius from a specified probability level.
  • Explain why pairwise distances concentrate as dimension grows.
  • Quantify how fixed-radius neighborhoods become sparse.
  • Relate geometric sparsity to the limitations of local KNN predictions.

Why Dimension Changes What “Near” Means

K-nearest-neighbor (KNN) methods predict from observations close to a query point. That description sounds simple, but “close” becomes harder to interpret as the number of predictors grows. A region that occupies a useful fraction of a one-dimensional range may cover only a tiny fraction of a high-dimensional predictor space. At the same time, distances between observations can become more alike, so the nearest point may not be much nearer than many other points.

These effects are called the curse of dimensionality. They do not imply that KNN must fail whenever there are many predictors. They explain why its local-information advantage can weaken: a neighborhood may contain few observations unless it is made broad, and a broad neighborhood may include points that differ substantially in their predictor values.

Definition: The dimension \(p\) is the number of predictor coordinates used to represent an observation. The curse of dimensionality refers to the rapid growth in the amount of data needed to represent or estimate local behavior as \(p\) increases. In KNN, two important manifestations are sparse local neighborhoods and concentration of distances.

Neighborhood Volume in a Hypercube

For a clean geometric calculation, suppose predictor vectors are distributed uniformly in the unit hypercube \([0,1]^p\), and place the query point at its center, \((1/2,\ldots,1/2)\). Use the maximum-coordinate distance \(d_{\infty}(\mathbf{x},\mathbf{z})=\max_j|x_j-z_j|\). A ball of radius \(r\leq 1/2\) around the center is a cube with side length \(2r\). Its volume, and therefore the probability that a random uniform observation falls inside it, is \((2r)^p\).

$$ P\{d_{\infty}(\mathbf{X},\mathbf{z})\leq r\}=(2r)^p,\qquad 0\leq r\leq \frac12. $$

The exponent \(p\) is the key. At a fixed radius smaller than \(1/2\), each added coordinate multiplies the neighborhood fraction by another factor of \(2r\). A radius that seems modest in each coordinate can therefore enclose very little probability mass in a high-dimensional space.

Worked Example: Same Neighborhood Fraction, Different Dimensions

Assume a hypothetical predictor vector is uniformly distributed in a unit hypercube, and a query lies at its center. A maximum-coordinate neighborhood must contain \(q=0.04\) of the predictor-space probability. Find its radius for \(p=2\) and \(p=8\), and explain the difference.

Method. For a centered maximum-coordinate neighborhood, \(q=(2r)^p\). Solving for \(r\) gives \(r=\tfrac12 q^{1/p}\).

For \(p=2\), \(r=\tfrac12(0.04)^{1/2}=\tfrac12(0.2)=0.1000\). Checking, \((2r)^2=(0.2)^2=0.04\).

For \(p=8\), \(r=\tfrac12(0.04)^{1/8}\). Since \(\ln(0.04)/8\approx -0.40236\), \((0.04)^{1/8}\approx e^{-0.40236}\approx0.6687\). Thus \(r\approx0.3344\).

The same probability fraction requires a radius more than three times as large in eight dimensions as in two. The calculation is consistent: \((2(0.3344))^8\) is approximately \(0.04\), with the small discrepancy due to rounding. Common mistake avoided: taking the \(p\)th root but forgetting to divide by 2. The side length is \(2r\), not \(r\).

This calculation also gives a sample-size implication. If the neighborhood fraction is \(q\), a sample of \(n\) independent observations has expected count \(nq\) in that region. To expect \(k\) observations, one needs \(n\approx k/q\). For fixed radius \(r\), \(q=(2r)^p\), so the required sample size grows roughly as \(k/(2r)^p\). Maintaining a fixed level of local detail can therefore demand a rapidly increasing data set.

Worked Example: A Fixed Radius Becomes Sparse

Suppose \(n=10{,}000\) independent predictor vectors are uniform in a unit hypercube. The query is at the center, and a maximum-coordinate neighborhood has radius \(r=0.1\). Compare the expected number of observations in the neighborhood for \(p=2\) and \(p=8\). For \(p=8\), also find the approximate probability that the neighborhood contains no observations.

Method. The neighborhood fraction is \(q=(2r)^p=(0.2)^p\). The count has a binomial distribution with parameters \(n\) and \(q\), so its expectation is \(nq\), and the probability of zero observations is \((1-q)^n\).

For \(p=2\), \(q=(0.2)^2=0.04\), giving expected count \(10{,}000(0.04)=400\).

For \(p=8\), \(q=(0.2)^8=0.00000256\). The expected count is \(10{,}000(0.00000256)=0.0256\). The probability of no observations is \((1-0.00000256)^{10{,}000}\approx e^{-0.0256}\approx0.9747\). Thus the probability of at least one observation is approximately \(1-0.9747=0.0253\).

The neighborhood that contained 400 observations in two dimensions is very likely to be empty in eight dimensions. The approximation uses \((1-q)^n\approx e^{-nq}\), which is accurate here because \(q\) is small. Common mistake avoided: treating the expected count \(0.0256\) as a probability. It is a mean count; the probability of at least one point is a separate quantity.

Nearest Neighbors Can Still Be Far Away

The nearest observation’s distance can also be analyzed directly. Under the same uniform-hypercube assumptions, let \(R\) be the distance from the center query to its nearest observation among \(n\) independent observations, using maximum-coordinate distance. The probability that one observation is outside radius \(r\) is \(1-(2r)^p\). Independence means all \(n\) observations are outside with probability \([1-(2r)^p]^n\).

$$ P(R\leq r)=1-\left[1-(2r)^p\right]^n,\qquad 0\leq r\leq\frac12. $$

The median nearest-neighbor radius is the value \(r\) for which \(P(R\leq r)=0.5\). Solving this equation gives \(r=\tfrac12[1-0.5^{1/n}]^{1/p}\). This is a median, not an expected distance; the distinction matters when describing what a “typical” nearest neighbor means.

Worked Example: Median Nearest-Neighbor Radius

Assume \(n=100\) independent observations are uniform in a three-dimensional unit cube. A query is at the cube’s center, and distance is measured by the maximum-coordinate metric. Find the median nearest-neighbor radius.

Method. Set the nearest-neighbor distribution equal to 0.5 and solve: \(1-[1-(2r)^3]^{100}=0.5\). Therefore \([1-(2r)^3]^{100}=0.5\), so \(1-(2r)^3=0.5^{1/100}\), and \(r=\tfrac12[1-0.5^{1/100}]^{1/3}\).

Now \(0.5^{1/100}=e^{\ln(0.5)/100}\approx e^{-0.00693147}\approx0.9930925\). Hence \(1-0.5^{1/100}\approx0.0069075\), whose cube root is approximately \(0.19045\). The radius is therefore \(0.19045/2\approx0.09522\), or 0.0952 to four decimal places.

As a check, the radius gives \((2r)^3\approx0.0069075\), so the probability that all 100 observations miss the neighborhood is approximately \((1-0.0069075)^{100}=0.5\). Common mistake avoided: rounding the small quantity inside the cube root too early. Its cube root is about \(0.19045\), before the final division by 2.

Why Distances Concentrate

Volume explains sparse local neighborhoods. A second effect is that distances between random points can become less variable relative to their typical size. The following derivation uses independent coordinates \(U_j,V_j\), each uniformly distributed on \([0,1]\), for two random points. It concerns squared Euclidean distance and does not require the query to be at the center.

Derivation: For one coordinate, let \(W=(U-V)^2\). Independence and uniformity give \(E[W]=E[U^2]+E[V^2]-2E[U]E[V]=1/3+1/3-2(1/2)(1/2)=1/6\). Also, integrating over the unit square gives \(E[(U-V)^4]=1/15\). Therefore \(\operatorname{Var}(W)=1/15-(1/6)^2=7/180\). Across \(p\) independent coordinates, squared Euclidean distance \(D^2=\sum_{j=1}^p (U_j-V_j)^2\) has mean \(p/6\) and variance \(7p/180\). Its coefficient of variation is \(\sqrt{7p/180}/(p/6)=\sqrt{7/5}/\sqrt{p}\). The relative standard deviation thus decreases in proportion to \(1/\sqrt p\).

This result concerns the spread of squared distances relative to their mean. As dimension increases, the relative spread shrinks, so randomly selected pairs tend to have squared distances closer to the typical value. Euclidean distances, which are the square roots of those quantities, also become more concentrated in relative terms. Concentration does not mean every distance is equal, and it does not by itself identify which predictor is irrelevant. It says that distance contrasts can become less pronounced.

Worked Example: Comparing Distance Variation Across Dimensions

For two independent uniform points in a unit hypercube, compare the mean and standard deviation of squared Euclidean distance when \(p=1\) and \(p=25\). Then compare their coefficients of variation.

Method. From the derivation, \(E[D^2]=p/6\) and \(\operatorname{Var}(D^2)=7p/180\).

For \(p=1\), the mean is \(1/6\approx0.1667\), the variance is \(7/180\approx0.03889\), and the standard deviation is \(\sqrt{7/180}\approx0.1972\). The coefficient of variation is \(0.1972/0.1667\approx1.1832\).

For \(p=25\), the mean is \(25/6\approx4.1667\), the variance is \(175/180=35/36\approx0.9722\), and the standard deviation is \(\sqrt{35/36}\approx0.9860\). The coefficient of variation is \(0.9860/4.1667\approx0.2366\). Equivalently, the formula gives \(\sqrt{7/5}/\sqrt{25}\approx0.2366\).

The standard deviation itself is larger in 25 dimensions, but the mean grows faster; the relative spread is much smaller. The check is that the coefficient of variation falls by a factor of five when dimension rises from 1 to 25, exactly as the \(1/\sqrt p\) formula predicts. Common mistake avoided: concluding that distances are less concentrated because their absolute standard deviation increased.

Implications for KNN and Exam Reasoning

KNN relies on nearby observations being informative about the query. When a fixed-radius neighborhood becomes sparse, an analyst may need a larger radius or a larger number of neighbors to obtain enough observations. A broader neighborhood can reduce the locality of the prediction: points can be far from the query in several coordinates even if they are among the available nearest neighbors. Distance concentration compounds the issue because the nearest point may offer less separation from other candidate points than it would in low dimension.

The geometric calculations use idealized assumptions: uniform independent predictors in a unit hypercube, a centered query for the neighborhood-volume formulas, and maximum-coordinate distance where stated. Actual predictor distributions may be clustered, correlated, bounded differently, or concentrated near a lower-dimensional structure. Thus these calculations explain a mechanism; they do not provide a universal numerical prediction for every data set.

In applications, the appropriate predictor representation and distance are essential. The earlier material on distance choices, feature weighting, correlated predictors, and irrelevant predictors addresses ways predictor geometry can be altered. The curse of dimensionality remains a useful warning even after such choices: if useful local observations are scarce, simply increasing the number of coordinates does not guarantee more useful information.

  • Check the geometry. State the distance, the data-space assumptions, and whether the query is interior before using a neighborhood-volume formula.
  • Separate count summaries. \(nq\) is an expected count; \(1-(1-q)^n\) is the probability of at least one observation.
  • Interpret spread relatively. A larger absolute standard deviation can coexist with a smaller coefficient of variation.
  • Do not overgeneralize. High dimension signals a possible loss of locality, not a theorem that every KNN prediction is inaccurate.

These geometric and numerical relationships are aligned with the SOA Exam SRM (Statistics for Risk Modeling) syllabus. The central exam habit is to connect dimension, neighborhood fraction, sample size, and distance spread rather than treating a distance calculation as if its interpretation were unchanged across dimensions.

Check Your Understanding

Use the stated uniform-hypercube assumptions and show the main calculation before checking each answer.

  1. A query is at the center of a four-dimensional unit hypercube. Under maximum-coordinate distance, what fraction of the space is within radius \(0.15\)? (Answer: \((0.30)^4=0.0081\).)
  2. For 200 independent uniform points in a two-dimensional unit square, find the median maximum-coordinate distance from the center query. Give the exact expression and round to four decimals. (Answer: \(\tfrac12[1-0.5^{1/200}]^{1/2}\approx0.0294\).)
  3. In a six-dimensional unit hypercube, a centered maximum-coordinate neighborhood has radius \(0.2\). If 500 points are sampled independently and uniformly, find the expected count and the probability of at least one point. (Answer: \(q=(0.4)^6=0.004096\); expected count \(500q=2.048\); probability \(1-(1-0.004096)^{500}\approx0.8715\).)
  4. For two independent uniform points in a nine-dimensional unit hypercube, find the mean and variance of squared Euclidean distance. (Answer: mean \(9/6=1.5\); variance \(7(9)/180=0.35\).)
  5. A centered maximum-coordinate neighborhood in four dimensions must contain \(q=0.02\) of the space. Find its radius and the expected number of points in a sample of 2,500 independent uniform observations. (Answer: \(r=\tfrac12(0.02)^{1/4}\approx0.1880\); expected count \(2{,}500(0.02)=50\).)
Clinical Biostats