Introduction to K-Nearest Neighbor Algorithm

Introduction to K-Nearest Neighbor Algorithm

1 What is the K-nearest neighbor algorithm

  • Infer your category based on your "neighbors"

1.1 The concept of K-Nearest Neighbor Algorithm (KNN)  [it is to judge which category you belong to through your "neighbors"]

The K Nearest Neighbor algorithm is also called the KNN algorithm. This algorithm is a relatively classic algorithm in machine learning. In general, the KNN algorithm is relatively easy to understand.

  • definition

If most of the k most similar (ie, the nearest neighbors in the feature space) samples of a sample in the feature space belong to a certain category , the sample also belongs to this category.

Source: KNN algorithm was originally a classification algorithm proposed by Cover and Hart

  • Distance formula

The distance between two samples can be calculated by the following formula, also called Euclidean distance. The distance formula will be discussed later

1.2 Analysis of movie types

Suppose we have a few movies now

among them? No. Movie I don’t know the category, how to predict? We can use the idea of ​​K nearest neighbor algorithm

Calculate the distance between each movie and the predicted movie separately, and then solve

[If there are few samples, errors may occur] [k is generally an odd number]

Guess you like

Origin blog.csdn.net/weixin_44799217/article/details/114261303