How math helps us understand what’s close, far, and similar, just like machines do.

The Pizza Map

Imagine you and your friend both love pizza. There are two pizza places in town: one near your school and another across the river. When you get hungry, which one do you go to? Probably the one that’s closer.

Closest Pizza Wins School Pizza A Pizza B You d(A)=? d(B)=? Choose: Pizza A (closer)
People and computers often pick what’s closest. Measuring distance helps decide.

That simple choice — picking what’s closest — is something both people and computers do all the time. To make that decision, you need to understand distance.


What Is Distance?

Distance tells us how far apart two points are.
In math, we often find distance using coordinates on a grid.

If you have two points, like (1, 1) and (4, 5), you can imagine drawing a right triangle between them. The distance is the length of the triangle’s diagonal.
Using the Pythagorean theorem, you can find it like this: (Note: is radical root of 2, thus 4=2, 9=3, √16=4, 25=5, etc)

distance = √((x₂ – x₁)² + (y₂ – y₁)²)

In our example:
√((4 – 1)² + (5 – 1)²) = √(9 + 16) = √25 = 5

So those two points are five units apart.


Try It Yourself — The Grid Game

Draw a simple coordinate grid on paper. Pick two points and calculate the distance between them.
Try placing points farther apart or closer together and see how the numbers change.

If you want to make it more visual, plot the points on an online graphing tool like Desmos. You can even color-code “close” and “far” points.

Try It — The Grid Game A B Distance: —
Click inside the grid to place A and B, then compare “close” vs “far”.
Optional: Open Desmos

The Idea of Space

When we measure distance between two places on a map, we’re working in two dimensions — up and across.
But in machine learning, data often lives in spaces with many more dimensions.

For example, a computer comparing two songs might look at things like:

  • Speed (tempo)
  • Mood (energy)
  • Instrument type
  • Lyrics

Each of these acts like a new dimension. The more features we add, the higher-dimensional the “space” becomes. Machines use math to measure distance in those invisible spaces — to find what’s most similar.


The Similarity Challenge

Imagine plotting your friends on a graph based on two qualities: how much they like sports (x-axis) and how much they like reading (y-axis).
Friends who are close on the graph have similar interests.
Friends who are far apart are very different.

That’s how computers decide which movie, song, or product you might like next — by finding what’s closest to your past choices in “data space.”


Thinking Like a Data Scientist

Distance isn’t just about physical space — it’s about similarity.
When a machine says two photos look alike, or two shoppers have similar tastes, it’s using math to measure how far apart their data points are.

Closer means more similar.
Farther means less similar.


How This Connects to Machine Learning

A simple but powerful algorithm called K-Nearest Neighbors (KNN) uses this exact idea.
When you ask a computer to classify something — like whether an image shows a dog or a cat — it looks at nearby examples.
If most of the closest data points are dogs, the computer guesses “dog.”

That’s math and distance working together to help machines “recognize” things.

KNN: Nearest Neighbors ? k=3 → prediction: —
Circles = “dog” examples, squares = “cat” examples. KNN predicts “?” by voting among the closest points.

Takeaway Message

Distance isn’t just about where things are — it’s about how similar they are.
By measuring closeness in data, both people and machines can make smart decisions about what belongs together.


Optional Extensions

  • For extra exploration, try plotting your own “interest map” — choose two hobbies and score yourself and your friends from 1 to 10 on each. Plot those points and see who ends up closest to you.
  • You can also use graphing tools to visualize real-world data — like cities by temperature and rainfall — and look for clusters of similar places.

By jess