Skip to content
nickgillian edited this page Aug 14, 2016 · 1 revision

KNN

Description

The K-Nearest Neighbors (KNN) classifier is a simple classifier that works well on basic recognition problems, however it can be slow for real-time prediction if there are a large number of training examples and is not robust to noisy data.

The KNN algorithm is part of the GRT classification modules.

Advantages

The K-Nearest Neighbors (KNN) classifier is a very simple classifier that works well on basic recognition problems.

Disadvantages

The main disadvantage of the KNN algorithm is that it is a lazy learner, i.e. it does not learn anything from the training data and simply uses the training data itself for classification. To predict the label of a new instance the KNN algorithm will find the K closest neighbors to the new instance from the training data, the predicted class label will then be set as the most common label among the K closest neighboring points. The main disadvantage of this approach is that the algorithm must compute the distance and sort all the training data at each prediction, which can be slow if there are a large number of training examples. Another disadvantage of this approach is that the algorithm does not learn anything from the training data, which can result in the algorithm not generalizing well and also not being robust to noisy data. Further, changing K can change the resulting predicted class label.

Training Data Format

You should use the GRT ClassificationData data structure to train the KNN classifier.

Example

KNN Example