# K Nearest Neighbors¶

Sanjiv R. Das

## What is kNN?¶

• This is one of the simplest algorithms for classification and grouping.

• Simply define a distance metric over a set of observations, each with $M$ characteristics, i.e., $x_1,x_2,...,x_M$.

• Compute the pairwise distance between each pair of observations, using any of the standard metrics. For example, Euclidian distance between data $x$ and $y$:
$$d = \sqrt{\sum_{i=1}^M (x_i - y_i)^2}$$
• Next, fix $k$, the number of nearest neighbors in the population to be considered.

• Finally, assign the category based on which one has the majority of nearest neighbors to the case we are trying to classify.