Glossary

What is K-nearest neighbors?

In Turkish: K-en yakın komşu (KNN) · Topic: Math foundations

A simple method that classifies a new example, or predicts its value, by looking at the labels of the k closest examples in the training data. It rests on the assumption that similar things sit close together.

How does it work?

During training the model learns almost nothing; it simply stores the labeled examples. When a new example arrives, its distance to every stored record is computed and the k nearest neighbors are picked. In classification the neighbors vote and the majority class wins; in numeric prediction their values are averaged. A small k is sensitive to noise, while a large k blurs the details. Since distance is involved, it matters that features are brought to the same scale.

Why does it matter?

Because it is easy to understand and implement, it is often used as a baseline model. The idea of finding similar items underlies recommendation systems and vector search. It slows down as data grows and suffers badly from the curse of dimensionality. At large scale, approximate nearest neighbor methods are therefore preferred.

Example

A movie site can recommend films to a user by looking at what the five users with the most similar tastes have enjoyed.

FAQ

What should k be?

There is no single right value; different values are usually tested with cross-validation. In binary classification odd numbers are common to avoid ties.

Why is KNN called a lazy learner?

It builds no generalizing model during training and leaves the work for prediction time. That makes training fast but prediction slow on large datasets.

All terms