6.6k views
2 votes
What is the k-nearest neighbor (k-NN) algorithm?

User Allencharp
by
7.8k points

1 Answer

3 votes

Final answer:

The k-nearest neighbor (k-NN) algorithm is a method used for classification and regression that works by finding the 'k' closest training examples to a new data point and predicting its label based on these neighbors.

Step-by-step explanation:

The k-nearest neighbor (k-NN) algorithm is a non-parametric method used for classification and regression. In both cases, the input consists of the k closest training examples in the feature space. 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).
  • In k-NN regression, the output is the property value for the object. This value is the average of the values of its k nearest neighbors.

k-NN is a type of instance-based learning, or lazy learning, where the function is only approximated locally and all computation is deferred until classification. The algorithm doesn't explicitly learn a model. Instead, it memorizes the training instances which are then used as 'knowledge' for the prediction phase. Given a new instance of a data point, k-NN will look at the 'k' closest labeled data points from the training set to determine the best label for the new point.

User Jero Toryaki
by
8.7k points