Our first learning system will be the k-nearest neighbors (kNN) classifier. I will describe how the classifier makes predictions, the important hyperparameters it uses, and the problems that are faced by the classifier. Throughout, I will be using the classifier to predict species of iris flowers. So, let's go ahead and start a Jupyter Notebook for this classifier:
- The first thing we're going to do is load in the dataset and other required functions, as follows:
![](https://static.packt-cdn.com/products/9781838823733/graphics/assets/d3dd0a2b-cf2d-4738-99d4-9602103c6507.png)
The iris dataset is provided with sklearn. It is one of their example datasets, and is well known.
- Then, we will load in an object that contains the iris data and save that into Python objects:
![](https://static.packt-cdn.com/products/9781838823733/graphics/assets/792d3b68-8dd1-4b35-a344-a7de6b70f0ff.png)
- Then, we will divide the dataset into training and test data by using the following lines of code:
![](https://static.packt-cdn.com/products/9781838823733/graphics/assets/73dc01eb-8bc1-4897-b4c1-64c9816b2c9c.png)
Here are the first five rows of the training data:
![](https://static.packt-cdn.com/products/9781838823733/graphics/assets/f849a126-3e6c-42a6-9256-8e6228a69706.png)
Here are the first five labels...