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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.