Part II · Chapter 5

Ask Your Neighbors

Judging a mystery newcomer purely by the company it keeps.

In Part I, every machine we built tried to summarize the world with a single clean rule—a straight rod, or a straight dividing curtain. That works beautifully when two groups sit neatly on opposite sides of a line.

But what if the map isn't neat at all? Imagine a city where cozy bookshop districts wrap around bustling night markets in twisting pockets and curved streets. No straight fence could ever separate them.

So let's throw away fences altogether. Suppose a mystery house appears on the map and you want to guess what kind of neighborhood it belongs to. You don't need a grand theory of the whole city. You can simply knock on the doors of the closest houses right next to it and take a vote.

The Core Visual Idea

To judge a mystery newcomer, draw a circle around it and grow that circle outward until it catches a chosen number of closest neighbors. Whichever color has the most votes inside the circle wins.

Move the Mystery Dot

Below is a map of two rival tribes: Blue and Gold. Notice that a couple of quirky lone dots live deep inside the other side's territory—just like real life, where an eccentric house pops up in an unexpected street.

Drag the glowing white Mystery Dot around the map, and change how many neighbors it asks. We keep the slider on odd numbers so the vote can never end in a tie.

Interactive Move the Mystery Dot
Drag or click anywhere on the map to move the glowing Mystery Dot
4 Gold vs. 1 Blue → Gold wins!
1 Blue
4 Gold

Try clicking Jump Near a Quirky Dot and sliding Neighbors Asked down to 1. When you only ask a single neighbor, that one eccentric house completely fools the Mystery Dot! Bump the slider up to 5 or 7, and the surrounding majority immediately outvotes the lone outlier.

Now push the slider all the way up to 15. The circle has to stretch across half the map just to find enough voters. Local flavor fades away—and if you asked almost everyone in the city, the bigger tribe would simply win everywhere, no matter where the Mystery Dot stood.

How Neighborhood Size Reshapes the Whole Map

Imagine placing our Mystery Dot at every single spot on the board and painting that spot with whichever color wins the vote. Suddenly, the hidden territory map springs into view—even though we never drew a single line!

Switch between 1 Neighbor, 5 Neighbors, and 15 Neighbors below to watch how the entire map transforms.

Interactive Territory Map by Neighborhood Size
Compare jagged islands, smooth borders, and broad sweeping zones
Smooth natural borders
Asking 5 neighbors smooths out lone quirks while keeping the natural curve of each tribe.

Look closely at the contrast between the three maps:

Takeaway

You don't always need to summarize examples into a line or a formula. Simply keeping the map and letting the closest neighbors vote can trace any curved shape—as long as you choose a neighborhood size that isn't fooled by one quirk and isn't so huge that it blurs the map away.

What do people call this in the wild? Optional: see the textbook terms behind voting neighbors and territory maps.
Asking the Closest Neighbors
k-Nearest Neighbors (k-NN)
One of the simplest and most intuitive methods in machine learning: classify a new point by the majority vote of its closest known examples.
Number of Neighbors Asked
The value "k"
Choosing how many neighbors get a vote—small values hug every quirk, while larger values smooth the boundary out.
Measuring How Close Two Dots Are
Distance Metric
The ruler used to decide who counts as "closest," most often straight-line distance across the map.
Remembering Every Example Without Drawing a Formula
Lazy / Instance-Based Learning
Instead of boiling examples down into a line ahead of time, the machine keeps all examples on hand and checks them on the spot.