Sklearn's machine learning path: K-Nearest neighbor algorithm (KNN)

Source: Internet
Author: User
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

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.