Appreciated that the value of k KNN algorithm

To facilitate learning his collection, reproduced Bowen from: https: //blog.csdn.net/llhwx/article/details/102652798

knn prediction algorithm refers to centralize all of the images of each image and comparing the training set to find out in the training set and a prediction picture which is closest to the image, the image of the label to this prediction picture. Method of image matrix is ​​subtracted and the absolute value, and then the resulting pixel matrix elements are added, the result is minimum is found, we say that the minimum value of the image generated with the closest prediction.

The above mentioned algorithm is knn case when k is equal to 1, which method allows to determine a minimum prediction image of the label and some absolute, error-prone results in some coincidence. For example: two different objects is the background color, and they tend to produce a subtraction relatively small value.

 

 


model shown above k = 1 corresponding to: left point represents the training set, as their color represents a certain category, the blank around the point can be seen as a prediction set. Now the magnitude of distance according to the entire image is divided into regions of different colors. When k is 1, the classification result shown to the right can be seen in FIG violet area contains a green dot area, according to experience, occurs in the vicinity of a large number of points purple purple most likely region, However, due to the green dot (in fact, this point is called noise), so that the result of an error has occurred. As this chart below, let us predict the most likely to be dashed point what color. Of course, it is red. Back to the idea knn algorithm, with only a minimum when we judge the color of the point, then there is an error of judgment may be the case.

 

 


Then it can be knn algorithm other values ​​of k value, when k is equal to 5, as shown in FIG classification result, a large number of red dots around the red area is surrounded by a large number of points are purple violet region, in green they are around a lot of green, a region, this case consistent with the predictions of our experience.

 

 


Back knn algorithm, if taken when k 5, which indicates the highest number found in the training set and the predicted 5 similar image picture, looking at five pictures of a label appears, the largest number of occurrences shall be the predicted label image. If the number of occurrences as much as it means a blank area in the figure is.

----------split line----------

For example: if k = 1 to find out and need to determine a value of the nearest neighbor. According to which category they belong to a data value discrimination need to be classified. K = 1 but often prone to error, such as the above-mentioned background, if the same two images, but different objects, such discriminated sometimes inaccurate. K should generally take a little big, look for some of the nearest neighbor is compared with the value. Comprehensive judgment to classify.

knn general algorithm is to find out from discrimination point with which the tag by calculating the minimum Euclidean distance. Note that the above-mentioned method for an image: the absolute value of subtracting the image matrix phase, the resulting pixel matrix of each element and then adding the minimum is found, it is needed to distinguish the image belongs to the classification corresponding to the minimum the image class.

 

Guess you like

Origin www.cnblogs.com/MINGYOUR/p/11827431.html