Training a kNN classifier

Training a kNN classifier is easy. First, you need to load in the training data, which will be used for every classification. After we do this, we receive a new data point that we want to classify, as shown in the following diagram:

We compute the distance of the data point from each point in the training set, as shown in the following diagram:

Then, we determine the k nearest points, as shown in the following diagram:

In this diagram, we can see that k is 3.

The most common class among those nearest points is the ...

Get Training Systems Using Python Statistical Modeling now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.