# k-nearest neighbors algorithm

## Non-parametric classification method / From Wikipedia, the free encyclopedia

#### Dear Wikiwand AI, let's keep it short by simply answering these key questions:

Can you list the top facts and stats about K-nearest neighbors algorithm?

Summarize this article for a 10 year old

In statistics, the ** k-nearest neighbors algorithm** (

**) is a non-parametric supervised learning method first developed by Evelyn Fix and Joseph Hodges in 1951,**

*k*-NN^{[1]}and later expanded by Thomas Cover.

^{[2]}It is used for classification and regression. In both cases, the input consists of the

*k*closest training examples in a data set. The output depends on whether

*k*-NN is used for classification or regression:

- In
*k-NN classification*, the output is a class membership. An object is classified by a plurality vote of its neighbors, with the object being assigned to the class most common among its*k*nearest neighbors (*k*is a positive integer, typically small). If*k*= 1, then the object is simply assigned to the class of that single nearest neighbor. - In
*k-NN regression*, the output is the property value for the object. This value is the average of the values of*k*nearest neighbors. If*k*= 1, then the output is simply assigned to the value of that single nearest neighbor.

*k*-NN is a type of classification where the function is only approximated locally and all computation is deferred until function evaluation. Since this algorithm relies on distance for classification, if the features represent different physical units or come in vastly different scales then normalizing the training data can improve its accuracy dramatically.^{[3]}

Both for classification and regression, a useful technique can be to assign weights to the contributions of the neighbors, so that the nearer neighbors contribute more to the average than the more distant ones. For example, a common weighting scheme consists in giving each neighbor a weight of 1/*d*, where *d* is the distance to the neighbor.^{[4]}

The neighbors are taken from a set of objects for which the class (for *k*-NN classification) or the object property value (for *k*-NN regression) is known. This can be thought of as the training set for the algorithm, though no explicit training step is required.

A peculiarity of the *k*-NN algorithm is that it is sensitive to the local structure of the data.