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
- Calculation of the test object to the training set distance for each object
- Sort according to distance from the
- Select the current test object k closest training objects, as a neighbor of the test object
- This statistical category k neighbors frequency
- 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