WeCodeAcademy

k-Nearest Neighbours

KNN classifies a new point by looking at its k closest neighbours in the training data and taking a vote. There is no real training: it just remembers the examples. Choose k with care: a very small k follows noise, a very large k blurs real differences.

Examplepython
Open in editor »
Quick check

How does KNN decide the class of a new point?

Your turn: write the code

Classify an animal of 28 kg and 62 cm and print the class number.

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.