
Nearest Neighbors and the Choice of Distance
A neighbor votes only after someone defines distance. Compare two rules on a floor grid, then see how units, neighborhood size and unfamiliar cases change the meaning of a prediction.
स्रोत
पूरा पाठ सारांश
Lay three sample cards on a floor grid. Each card describes a piece of fruit by its mass and its widest diameter, and carries a label from someone who has identified it. A fourth fruit has measurements but no label. A nearest-neighbor classifier looks for examples with measurements like these and lets their labels inform a prediction. The person designing the classifier decides what counts as near. That decision can change which examples get a vote.
Imagine two differences measured from the unknown fruit. One neighbor differs by two units horizontally and two vertically. Another differs by three horizontally and zero vertically. If moving in any direction costs the straight-line distance, the first neighbor is closer: the diagonal is about 2.83 units long. If the rule adds horizontal and vertical travel, as on a grid of city streets, the distances become four and three. The second neighbor is now closer. Both calculations are correct. They answer different questions about how differences should accumulate.
Units matter even before choosing a distance rule. A change from kilograms to grams multiplies numerical differences on the mass axis by a thousand. The fruit stays the same, yet its nearest neighbor can change. One approach is to express each measurement relative to the spread of that feature in the training data. This puts the scales on a more comparable footing. It still leaves a substantive question: should mass and diameter contribute equally to this particular identification task?
The letter k tells the classifier how many neighbors to consult. With k equal to one, a single mislabeled training card can determine the answer for nearby fruit. With three neighbors, two pear labels and one apple label give a pear prediction under an ordinary majority vote. If the dataset has very few examples of one variety, a larger neighborhood might drown them out. One can also give nearer examples more weight. The fraction of nearby cards carrying a label describes this neighborhood; it needs additional evaluation before being interpreted as a reliable probability.
For a classroom investigation, prepare a small labeled collection and set aside several cards before the class designs its rule. Let pairs plot the remaining examples, pick scales and a distance rule, and record the neighbors used in each decision. Invite them to disagree about an awkward case near the boundary. If they change the rule, let them try it on fresh cases. Repeatedly adjusting the rule to answer the same test cards makes those cards poor evidence about future performance.
Finish by placing an unfamiliar object well outside the plotted collection. It still has a nearest example; even an extremely long distance has a minimum. Ask students what information they would need before assigning the label. Their answers reveal whether they understand both parts of the method: retrieving the closest available examples and deciding whether the comparison is informative.


