It earns a place when
- Use it for small datasets where a meaningful distance exists and local smoothness is plausible.
- You can evaluate it against a credible baseline.
- Its output fits the decision and data constraints.
Machine learning models · Phase 2 · Lesson 12
Use similarity-based prediction and understand its dependence on distance, scale and local data density.
Use similarity-based prediction and understand its dependence on distance, scale and local data density.
To predict a new case, ask what happened to the most similar known cases. The model is a memory lookup with a distance rule.
For k neighbours, classification can use a majority vote and regression can average targets. Common distances include Euclidean distance, but the metric is part of the model.
Recommend a product to a new user by finding users with similar recent interactions. If one feature is measured in dollars and another in seconds, scaling affects who counts as similar.
When a result looks surprisingly good, inspect the split, target timing, error slices and data-generating process before celebrating.
Use this as a small experiment rather than a recipe to copy blindly. Change one thing, record the result and explain the change.
Answer from memory first. The buttons reveal feedback, but the durable step is explaining why.
1. What does kNN use at prediction time?
2. Why does feature scaling matter?
3. What is a common kNN weakness?
scikit-learn User Guide. Use the source for the deeper treatment after you can explain the lesson's core idea without looking.