k-Nearest Neighbours
Tell me your neighbours and I will tell you who you are. The k-nearest neighbours method (kNN) puts a new item in the group of its closest examples. There is no training step. In this lesson you build it in a few lines of NumPy.
New words
- Neighbour
- A known example that lies close to the new item.
- Distance
- A number that tells how far apart two items are.
- k
- How many neighbours we ask. We choose it ourselves.
- Majority vote
- The group with the most neighbours wins.
- Feature scaling
- Changing features so that they all use a similar range.
- Lazy learner
- A method that does no training. It just stores the data.
What you will learn
- Which fruit is this?
- How do you measure distance?
- Who are the nearest neighbours?
- How does the vote work?
- Which k is best?
- Why must features be on the same scale?
- Why is kNN slow at prediction time?
- Try it: place a new fruit
- Common mistakes
- Explain it to a friend
- Key takeaways
10 quiz questions at the end.
The full lesson, with interactive demos and the quiz, opens after you sign in with Google. It is free.