1. What is k nearest neighbor
Popular Will, if I were a sample, the KNN algorithm would be to find a few recent samples, see what categories they all belong to, and then select the category with the largest percentage of their category. KNN is the full name of K-nearestneighbor,k is the number of samples we are looking for, k=1 is to find the most recent samples, and then their own category is the category of the sample.
The KNN also calculates its distance from other samples, where there is more distance calculation method (depending on the parameter p≥1 p≥1 p \ge 1): Manhattan distance (Manhattan distance): when p=1 p = 1 p = 1 o'clock, the distance is calculated as: L1 (XI,XJ) =∑l=1n|xi−xj| L 1 (x i, x j) =∑l = 1 N | X i−x J | L_1 (X_i,x_j) =\sum_{l=1}^n|x_i-x_j| Euclidean distance (Euclidean distance): when p=2 p = 2 p = 2 o'clock, the distance is calculated as: L1 (XI,XJ) = (∑l=1n|xi−xj|2) 1 L (x i, x j) = (∑l = 1 N | x i −x J | 2) 1 2 l_1 (x_i,x_j) = (\sum_{l=1}^n|x_i-x_j|^2) ^\frac{1}{2} general form, distance formula is: L1 (XI,XJ) = (∑l=1