Lab 09: Length and Distance

Interactive tools for Chapter 9. Move vectors, compare data points, change feature scales, explore nearest neighbors, and watch distances behave strangely in high dimensions.

1. Vector Length

Length is the size of a vector. In two dimensions, it is the diagonal length from the Pythagorean theorem.

2. Distance Between Two Points

3. Distance Rules: L₁, L₂, and L∞

Different distance rules answer different questions. L₁ counts coordinate movement, L₂ measures straight-line distance, and L∞ asks for the worst coordinate difference.

4. Feature Scaling Trap

We compare a query apartment to three apartments using rent, size, distance-to-campus, and bedrooms. Use the slider to change the weight of rent. Notice how the nearest neighbor can change.

Raw distance can be dominated by the largest numerical feature. A distance calculation is also a modeling decision.

5. Nearest Neighbor Classifier

6. Image Distance

A small image can be flattened into a vector. Pixel distance is easy to compute, but it may not always agree with human visual similarity.

7. High-Dimensional Distance

As dimension grows, distances usually grow. Their relative spread often shrinks. This is one reason high-dimensional geometry can feel unlike the plane.

8. Matrix Transformations Change Distance

Reflection Questions

  1. What is the difference between a vector and its length?
  2. Why is distance between data points not automatically meaningful?
  3. When might Manhattan distance be better than Euclidean distance?
  4. What does standardization do before a distance calculation?
  5. Why can high-dimensional distance be surprising?