Loading…
Glossary term
A method that predicts based on the labels of the closest examples in the data.
To classify a new point, k-nearest neighbors finds the k most similar training points and takes a majority vote, or averages their values for regression. There is no training step; it just stores the data. It depends on a good notion of distance.
K-nearest neighbors
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier(n_neighbors=5).fit(X_train, y_train)It is one of the simplest ideas in machine learning and a useful baseline.