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?

  1. Ak = 3: red, k = 5: red
  2. Bk = 3: red, k = 5: blue
  3. 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.
Practice this topic Back to topic

Related calculators

Books on Machine Learning Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Machine Learning Basics questions

  1. Which of the following describes a support vector machine (SVM)?
  2. 20% of all emails are spam. A certain word appears in 50% of spam emails and in 5% of non-spam emails. Which is closest to the probability that an email containing this word is spam?
  3. Which logic function cannot be represented by a simple perceptron consisting only of input and output layers (a single neuron that outputs 0 or 1 with a threshold)?
  4. In a three-class classification, the values input to the softmax function (logits) are 3, 1 and 0. About how many times the second class's output (probability) is the first class's output? Which is closest?
  5. A small neural network with inputs x₁ = 1 and x₂ = 2 has two hidden neurons h₁ = ReLU(x₁ + x₂ − 1) and h₂ = ReLU(x₁ − 2x₂ + 1), and output y = 2h₁ + 3h₂ + 1. What is the value of y?