Getting the AI KNN learning algorithm

First, what is KNN algorithm

kNN (k-NearestNeighbor), that is, k-nearest neighbor algorithm. As the name suggests, the so-called K-nearest neighbor, k nearest neighbor is mean. That it is, in the data set that can be used to represent each sample away from his most recent k neighbors. As an example, centralized find the nearest K neighbors from all samples, and then determine the test object belongs to this category according to the K neighbors Category circumstances.

 

Two, KNN algorithm execution process

  1. Calculation of the test object to the training set distance for each object
  2. Sort according to distance from the
  3. Select the current test object k closest training objects, as a neighbor of the test object
  4. This statistical category k neighbors frequency
  5. k neighbors in the highest frequency categories, is the category of the test object

Three, KNN algorithm What are the characteristics

   1. Simple and plain, suitable for entry-AI

        2. Classification can do can do return

        3. The machine learning algorithms belonging supervised

        4.kNN algorithm does not model, the model is actually a training data set

Fourth, the code runs effect

1, algorithm

2, encapsulation algorithm

3, calling encapsulation algorithm

4, the interface mobilize Sklearn

 

Guess you like

Origin www.cnblogs.com/chaser24/p/12393099.html