Machine Learning Basics
The class of the 2D point (0, 0) is predicted with k-nearest neighbors. The training data consists of red points (1, 0), (3, 0) and (0, −3) and blue points (0, 2) and (−2, 1). Using Euclidean distance, which pair of predictions for k = 3 and k = 5 is correct?
- Ak = 3: red, k = 5: red
- Bk = 3: red, k = 5: blue
- Ck = 3: blue, k = 5: red
Show answer and explanation
Answer: C. k = 3: blue, k = 5: red
The distances from (0, 0) are 1 for red (1, 0), 2 for blue (0, 2), √5 ≈ 2.24 for blue (−2, 1), and 3 for both red (3, 0) and red (0, −3). For k = 3, the three nearest points are 1 red and 2 blue, so the majority vote gives blue; for k = 5, all the points are used, 3 red and 2 blue, giving red. k-nearest neighbors does no computation at training time and searches for nearby points at prediction time, and as shown here the result depends on k. Because it compares distances, standardization to align the units and scales of the features is important.
- A. For k = 3, the three nearest points are 1 red and 2 blue, so the majority vote gives blue.
- B. The results for k = 3 and k = 5 are reversed. k = 3 gives 2 blue and 1 red, and k = 5 gives 3 red and 2 blue.
- C. Correct. k = 3 gives blue with 2 blue and 1 red, and k = 5 gives red with 3 red and 2 blue.