3.1. Exercises

Finding Neighbours Questions

Nearest Neighbours True or False

Calculating the Distance to a Query Point

Instructions:
Running a coding exercise for the first time could take a bit of time for everything to load. Be patient, it could take a few minutes.

When you see ____ in a coding exercise, replace it with what you assume to be the correct code. Run it and see if you obtain the desired output. Submit your code to validate if you were correct.

Make sure you remove the hash (#) symbol in the coding portions of this question. We have commented them so that the line won’t execute and you can test your code after each step.

Let’s calculate the closet Pokémon in the training set to a Snoodle (our made-up Pokémon)!

Snoodle has the following feature vector.

[[53,  77,  43,  69,  80,  57,  5]]

Which Pokémon in the training set, most resembles a Snoodle?

Tasks:

  • Create a model and name it nn (make sure you are finding the single closest Pokémon).
  • Train your model on X_train.
  • Predict your Pokémon using kneighbors and save it in an object named snoodles_neighbour.
  • Which Pokémon (the name) is Snoodle most similar to? Save it in an object named snoodle_name.
Hint 1
  • Are you using NearestNeighbors(n_neighbors=1)?
  • Are you using nn.fit(X_train)?
  • Are you using nn.kneighbors(query_point) ?
  • Are you using train_df.iloc[snoodles_neighbour[1].item()]['name'] to get the name of the closest Pokémon?
Fully worked solution: