Junior Codes
Model Detectives

k-Nearest Neighbours (kNN) Explained for Kids

Guess by asking the most similar known examples to vote.

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

k-nearest neighbours, explained simply

k-nearest neighbours, or kNN, is one of the simplest machine learning methods, which makes it great for seeing how a model decides.

To classify something new, the model finds the k training examples most similar to it, its nearest neighbours. Each neighbour votes with its label, and the most popular label wins.

The value of k matters. With k = 1, one odd example can swing the answer. A larger k listens to more neighbours and smooths out oddities, but too large and it starts ignoring genuine local patterns.

Example: Who lives nearby?

  • A mystery creature appears on the map.
  • Its 5 nearest neighbours are 3 foxes and 2 cats.
  • With k = 5, the vote is 3 to 2, so the model guesses "fox".
  • With k = 1, it only asks the single closest neighbour, which happens to be a cat.

Try this

  • Stand in a room of family members and ask: who are my three nearest neighbours, and what do most of them like best?
  • Draw dots of two colours on paper, add a new dot, and colour it by its 3 nearest neighbours.
  • Try k = 1 and k = 7 on the same dot. Does the answer change?

Practise it in Wonderwild

“Ask the neighbouring creatures”

Discovery 9 in Model Detectives, one of 24 AI discoveries in Wonderwild.

Your child trains, tests and questions a small model in the browser with Pip. No coding needed. For ages 7+.

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

Questions parents and kids ask

What does the k mean in kNN?+

k is the number of neighbours the model asks. k = 3 means the three closest training examples vote on the answer.

Is kNN used in real AI?+

Yes, in recommendation systems and search, and the idea of finding similar examples sits underneath many modern tools.

Prefer learning with a teacher?

Our live AI Explorers course teaches these ideas in small online classes led by a software engineer, with projects and feedback. Every live course also includes 12 months of full Wonderwild access for practice.

See the AI Explorers course