Nearest neighbor classifier (KNN)

Source: Internet
Author: User

First, Concept & significance

Find and test all training samples that are relatively close to the sample properties.

Using the most recent pro to determine the rationality of the class label, with the following words to best illustrate:

"If you walk like a duck, and you look like a duck, it's probably a duck," he said.


Second, the calculation steps:

1. Distance: Given the test object, calculate its distance from each object in the training set

2, looking for neighbors: delimit the nearest K-object, as the nearest neighbor of the test object

3, do classification: according to the K nearest neighbor attribution of the main category, to the test object classification

三、三个 Basic Elements

I, distance measurement



a) When p=2, for European-style distances:


B) When P=1, for Manhattan Distance:


II, Selection of K-values

The smaller the K value, the more complex the whole model is, and the easier it is to fit.

The larger the K value, the simpler the overall model, and the approximate error will increase (mis-classification)

Iii. Determination of test object categories

A) majority vote:


where V is the class designator, Yi is a nearest neighbor class designator,I(.) is the indicator function, if its argument is true, returns 1, otherwise, 0

b) Distance weighted vote:




Nearest neighbor classifier (KNN)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.