How to understand KNN algorithm in R language
How to understand the KNN algorithm in R language, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.
K-nearest neighbor (KNN) algorithm is one of the simplest classification algorithms, which belongs to supervised machine learning algorithm.
Algorithm flow
The core idea of KNN is to find out the k points closest to the points to be classified in the feature space. If most of these k points belong to a certain category, then the sample also belongs to this category.
The k value is usually an integer below 20. The picture below is a picture taken from the Internet. You can directly see that four of the five points closest to point x are red dots, so the category of point x is classified as red dots.
R language realization
To implement knn clustering in R, you can use the knn () function in the midpoint of the class package. In the following example, we use UCI's Breast Cancer characteristic dataset for demonstration. First, read the data on the network:
# read the data on the Internet and set the variable name
Url