Distance Weights Flip the Vote

A query point's five nearest neighbors, in order:

neighbor distance class
1 1.0 A
2 3.0 B
3 4.0 B
4 5.0 B
5 10.0 B

KNeighborsClassifier(n_neighbors=5) defaults to weights='uniform'; weights='distance' weights each neighbor by 1/d1/d. What does each setting predict?

A

uniform predicts B, and distance also predicts B by 22.0 to 1.0, since the weights are the distances themselves.

B

uniform predicts B by 4 votes to 1; distance predicts A, 1.000 against 0.883.

C

Both predict B: the closest point is still one neighbor, and no positive weighting can overturn a four-to-one majority.

D

Both predict A, since weights='distance' is the default and the nearest neighbor already dominates.