Learn Before
Concept

Classification Algorithm of K-Nearest Neighbors

K-nearest neighbors can be used to classify data. Given a training set X_train with labels y_train, and given a new instance x_test to be classified:

  • Find the k most similar instances (X_NN) to x_test that are in X_train.
  • Get the labels y_NN for the instances in X_NN.
  • Predict the label for x_test by combining the labels y_NN. The combination can be done through different methods, e.g., a simple majority vote can find the label that is the most common among the k most similar examples.

For example, if K = 1, then the first closest neighbor will be used to classify the unknown data point. If K = 14, then the 14 nearest neighbors will be used. If the data point falls between multiple clusters, then you choose the category that holds the most.

0

4

Updated 2021-02-27

Tags

Data Science