k-nearest neighbors

k-nearest neighbors predict from the k closest training examples: majority vote in classification, mean in regression. The model builds nothing during training and is sensitive to the scale of the variables, which must therefore be standardized. A small k overfits, a large k smooths too much.

Example

KNeighborsClassifier(n_neighbors=5).fit(X_train_s, y_train)

Related concepts

The whole glossary