Keras 2.x Projects
上QQ阅读APP看书,第一时间看更新

K-nearest neighbors

KNN is an algorithm that's used in pattern recognition for object classification based on the characteristics of the nearest objects. An object is classified according to the majority of the votes of its neighboring k cluster. The k integer is a positive integer that is typically not very large. If the value of k is 1, then the object is assigned to its neighbor's class. In a binary context in which there are only two classes, it is appropriate to choose k with an odd value to avoid being in a situation of parity. It is the simplest algorithm among those used in machine learning.

Therefore, KNN identifies the class of belonging to a tested sample based on its distance from stored and classified objects. In most cases, the Euclidean distance is used. On a bidimensional plane, the Euclidean distance represents the minimum distance between two points, which is essentially the straight line connecting two points on a graph. This distance is calculated as the square root of the sum of the squared difference between the elements of two vectors. An object is assigned to the class based on the majority vote of its neighbors, and then the most common among its KNN is chosen.