ML | Implementation of KNN classifier using Sklearn
Prerequisite: K-Nearest Neighbours Algorithm
K-Nearest Neighbors is one of the most basic yet essential classification algorithms in Machine Learning. It belongs to the supervised learning domain and finds intense application in pattern recognition, data mining and intrusion detection. It is widely disposable in real-life scenarios since it is non-parametric, meaning, it does not make any underlying assumptions about the distribution of data (as opposed to other algorithms such as GMM, which assume a Gaussian distribution of the given data).
This article will demonstrate how to implement the K-Nearest neighbors classifier algorithm using Sklearn library of Python.
Step 1: Importing the required Libraries
Step 2: Reading the Dataset
Step 3: Training the model
Step 4: Evaluating the model
We now try to find the optimum value for ‘k’ ie the number of nearest neighbors.
Step 5: Plotting the training and test scores graph
From the above scatter plot, we can come to the conclusion that the optimum value of k will be around 5.
Attention reader! Don’t stop learning now. Get hold of all the important Machine Learning Concepts with the Machine Learning Foundation Course at a student-friendly price and become industry ready.