nearest neighbor

A nearest neighbor is the data point in a reference set that has the smallest distance to a query point under a specified metric.

In machine learning and search, this idea extends to k-nearest neighbors (k-NN), where tasks such as classification and regression use the labels or target values of the k closest points.

Implementations typically compute distances, such as Euclidean or Manhattan and find neighbors either by brute-force scanning or by using spatial index structures like KD-trees or Ball Trees, depending on the dataset, dimensionality, and chosen metric.


By Leodanis Pozo Ramos • Updated Nov. 17, 2025