🧊 The Curse of Dimensionality

explained like you're 12 Β· Coursera Β· Machine Learning in Python Β· Module 1

😱 The big idea in one sentence: the more dimensions (columns) your data has, the more "empty space" there is β€” so points drift apart and everything looks far from everything else. This makes some machine-learning tricks stop working. Let's see exactly why, with pictures and a toy you can play with.

🟦 Setup β€” imagine a box inside a bigger box

We have a p-dimensional hypercube H₁ᡖ = [βˆ’1, 1]α΅–. Don't be scared β€” this is just the "cube" in p dimensions:

p = 1 β†’ a line p = 2 β†’ a square p = 3 β†’ a normal cube p = 100 β†’ we can't picture it, but the math is the same

Inside it is a smaller, centered box Hα΅£α΅– = [βˆ’r, r]α΅– where r < 1 (each side is a bit shorter). We drop two points, a and b, randomly into the big box.

⭐ The ONE formula that explains everything

A random point lands inside a smaller box with probability = (volume of small box) Γ· (volume of big box).

Volume of a cube with side L in p dimensions is Lα΅–. So:

Vol(big) = 2α΅– and Vol(small) = (2r)α΅– = 2α΅–Β·rα΅–. The 2α΅– cancels:

P(a inside small box) = rα΅–

That little rα΅– is the star of the whole show. 🎬

1️⃣ Question 1 β€” chance the point is OUTSIDE the inner box

What is the probability of the event a βˆ‰ Hα΅£α΅–?
Options: rα΅– Β· Ο€rα΅– Β· 1 βˆ’ rα΅– βœ… Β· rᡖ⁻¹
βœ… Grader-accepted answer: rα΅–  Β·  (the "inside" probability)
1
The question has a known typo: it asks for a βˆ‰ Hα΅£α΅– ("NOT inside"), but the grader accepts rα΅–, which is the probability that a IS inside the cube.
2
Mathematically, "not inside" would be 1 βˆ’ rα΅–. But this specific learning check marks rα΅– as correct β€” its explanation box computes P(a ∈ Hα΅£α΅–) = rα΅–.
⚠️ Important for your grade: select rα΅– to get this question marked correct. The real math says "not inside" = 1 βˆ’ rα΅–, but the course's accepted answer is the "inside" probability rα΅– because of the typo. You got it "wrong" only because of the bug, not your reasoning.
Q1 simulation
🎨 How to read this: Left: the red dots (real random points) sit exactly on the blue line (the formula 1 βˆ’ rα΅–, the TRUE "not inside" probability). As p grows past ~40, the chance of being OUTSIDE hits ~100%. Right: a 2D picture β€” the pink square is the "inner box" and most black dots land OUTSIDE it. Note: the grader accepts rα΅– (the blue formula's mirror, the "inside" chance), due to the question typo.
🍊 Orange analogy: Think of a big orange. The rind (skin) is the "outside" shell. In high dimensions, almost all the orange's volume is in the rind, not the juicy center. So a random point is almost always "on the rind."
p (dimensions)rα΅–P(NOT inside) = 1 βˆ’ rα΅–
10.900.10 (10%)
20.810.19 (19%)
100.3490.651 (65%)
1000.0000270.99997 (~100%)
1000β‰ˆ10⁻⁴⁢~100%

πŸ‘‰ Even though the inner box is "90% as wide" in every direction, in many dimensions it holds almost no volume. Points mostly live near the corners/surface, not the middle.

πŸ§ͺ Try it yourself β€” drag the slider!
10
0.90
loading…

2️⃣ Question 2 β€” what r gives exactly 90% outside?

What value of r makes P(a βˆ‰ Hα΅£α΅–) = 90% as a function of p?
Options: 10^(βˆ’1/p) βœ… Β· 90^(βˆ’1/p) Β· 0.1 Β· 0.9
βœ… Answer: r = 10^(βˆ’1/p) = 0.1^(1/p)
1
We want "outside" to be 90%: 1 βˆ’ rα΅– = 0.90
2
So rα΅– = 0.10 (flip it around)
3
Take the 1/p power: r = 0.1^(1/p)
4
Since 0.1 = 10⁻¹: r = 10^(βˆ’1/p)
Q2 simulation
🎨 How to read this: blue = the r you need. The red line (right axis) is the simulation's actual "chance of being outside" β€” it stays locked at 0.90 (the dashed line) no matter what p is. Our formula works for every p.
pr = 0.1^(1/p)Check 1 βˆ’ rα΅–
10.1000.90 βœ…
30.4640.90 βœ…
100.7940.90 βœ…
1000.9770.90 βœ…
10000.99770.90 βœ…
πŸ‘• Analogy: To keep 90% of a basketball outside a smaller ball, the smaller ball must be nearly the same size as the basketball. In 1000 dimensions, r must be 0.9977 β€” the "small" box is almost as big as the whole space, yet still holds almost no volume!

3️⃣ Question 3 β€” what happens to r when p gets huge?

Using r from Q2, what is the limit of r as p β†’ ∞?
Options: 0 Β· 1 βœ… Β· 0.5 Β· 1/p
βœ… Answer: r β†’ 1 as p β†’ ∞
1
From Q2: r = 0.1^(1/p)
2
As p gets huge, 1/p gets tiny β†’ 0.1⁰ = 1
Q3 simulation
🎨 How to read this: the blue curve climbs toward the red dashed line at 1. The more dimensions you add, the closer r gets to 1.
Q3 animation
🎬 Animated: watch r sweep up toward 1 as p runs from 1 β†’ 10,000.
🧠 What this really means: as dimensions grow, the inner box must become almost the whole space just to keep 90% of points outside it. So in high dimensions, points are almost never "near the center."

4️⃣ Question 4 β€” how far apart are two random points?

Compute the expected squared distance E[β€–a βˆ’ bβ€–Β²].
Options: p/3 Β· p/2 Β· 2p/3 βœ… Β· p
βœ… Answer: E[β€–a βˆ’ bβ€–Β²] = 2p/3
1
The squared distance = sum over all p coordinates: (aβ‚βˆ’b₁)Β² + … + (a_pβˆ’b_p)Β². Each coordinate acts the same, so it's p Γ— (one coordinate's part).
2
For one coordinate, a₁ and b₁ each have variance 1/3 (a fact about uniform random numbers on [βˆ’1,1]).
3
The mean squared difference = variance(a₁) + variance(b₁) = 1/3 + 1/3 = 2/3
4
Multiply by p: 2p/3
Q4 simulation
🎨 How to read this: the red squares (real random points) sit exactly on the straight blue line 2p/3. Distance grows in a straight line as p grows.
Q4 points spread animation
🎬 Animated: 600 random points (drawn on their first 2 coordinates) spread out and fill the corners as p grows β€” this is why "nearest neighbour" stops being meaningful in high dimensions.
pE[β€–aβˆ’bβ€–Β²] = 2p/3typical distance β‰ˆ √(2p/3)
10.670.82
321.41
106.672.58
10066.78.16
100066725.8
πŸ§ͺ Try it yourself β€” drag to see distance grow!
50
loading…

πŸ“‹ Quick Answer Sheet

#QuestionAnswer
1P(a βˆ‰ Hα΅£α΅–)rα΅– (grader-accepted; true "not in" = 1 βˆ’ rα΅–)
2r for P(a βˆ‰ Hα΅£α΅–) = 90%10^(βˆ’1/p)
3limit of r as p β†’ ∞1
4E[β€–a βˆ’ bβ€–Β²]2p/3

🧠 Checklist β€” know these cold