KNN
KNN is one of the simplest classification algorithms, and almost everything you need to know about its mechanism is presented in its name. In simple terms, to classify a new data object, KNN finds the K-nearest neighbors to the new data object from the training dataset and uses the label of those data objects to assign the likely label of the new data object.
It might be the case that KNN is too simple, and because of that, you do not fully understand its mechanism. Let's continue our learning, using the following example.
Example of using KNN for classification
We are going to continue working on the loan application problem that was introduced earlier. After completing the classification design, we specified Income and Credit Score as independent attributes and Default? as the dependent attribute. The following screenshot shows a dataset that can support this classification design. The dataset is from the CustomerLoan.csv
file: