K-Nearest Neighbors "for loop" Professor,
I know I need to create a for loop in the second problem of the homework to prevent myself from going through the tedious process of
calculating 49 distances by hand, however, I am having a significant amount of trouble figuring out how to get the loop code started.
Any advice on how to start the loop?
Answers and follow-up questions Answer or follow-up question 1
This should get you started:
You want a nested loop. The outer loop iterates over the new instances,
and the inner loop iterates over the training instances and computes the
distance for the current new instance.
For advances R users: you can simply vectorize the inner loop.
Mchel BallingsSign in to be able to add an answer or mark this question as resolved.