Supervised Learning—Classification Using K‐Nearest Neighbors (KNN)

Wei-Meng Lee · 2019

K -Nearest Neighbors (KNN) works by comparing the query instance's distance to the other training samples and selecting the K-nearest neighbors. This chapter explains how KNN works and how to derive the optimal k that minimizes the miscalculation of errors. The KNN function returns the class to which the test point belongs, as well as the indices of all the nearest k neighbors. The chapter explores how KNN can be implemented manually in Python and helps the coders to use the implementation provided by Scikit-learn. Using Scikit-learn's KNeighborsClassifier class help the coders to train a model on the Iris dataset using KNN. The chapter provides information of common use of KNN as a classification algorithm.

Read the paper · More papers on PaperTik