1
$\begingroup$

I have started reading the Introduction to statistical learning book. At the end of the chapters there are some exercises. I can find answers to the exercises but not necessarily how the answers were found in all scenarios. Below is a table where X1 = X2 = X3 = 0. It first asked to calculate the Euclidean distance which I understand to calculate as Abs(x1-y1)^2 + ....Abs(xn-yn)^2. The next questions that are asked is what is the predicted outcome for when K=1. The answer is Green because K=1 nearest neighbor is Observation 5. Next they ask for the predicted outcome for when K=3. The answer is Red because K's nearest neighbors are 2, 5, 6. What I cannot for the life of me figure out is how K's nearest neighbors are determined. For K=1 how do you come to the conclusion that Observation 5 is the nearest neighbor. Any help would be greatly appreciated, Thanks!

   Obs.   X1   X2   X3  EuclideanDistance   Y
   ---------------------------------------------
   1      0    3    0   3                   Red 
   2      2    0    0   2                   Red
   3      0    1    3   sqrt(10) ~ 3.2      Red
   4      0    1    2   sqrt(5) ~ 2.2       Green
   5      -1   0    1   sqrt(2) ~ 1.4       Green
   6      1    1    1   sqrt(3) ~ 1.7       Red
$\endgroup$
  • $\begingroup$ According to your table, Obs 5 has the lowest Euclidean distance to your test point (which doesn't seem to be mentioned in your question). So if you sort the points by distance and take the first K (=1) neighbors, you end up with Obs 5. $\endgroup$ – Ansari Nov 29 '16 at 22:24
  • $\begingroup$ So far k=1 you take the observation with the smallest euclidean distance and for k=3 you take the smallestime 3? $\endgroup$ – Lizzard Nov 29 '16 at 23:47
  • $\begingroup$ Yes, that comes from the definition of the 1 (or 3 or 5 etc.) "nearest" neighbors. $\endgroup$ – Ansari Nov 29 '16 at 23:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.