4.1. Exercises

Classifying Examples by Hand

Consider this toy dataset:

404 image

Question 1

404 image

Question 2

404 image

π‘˜-NN Classifiers True or False

Predicting with a π‘˜-NN-Classifier

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 try to classify some PokΓ©mon from the PokΓ©mon dataset. How well does our model do on the training data?

Tasks:

  • Create a KNeighborsClassifier model with n_neighbors equal to 5 and name it model.
  • Train your model on X_train and y_train (Hint: you may want to use .to_numpy()).
  • Score your model on the training set using .score() and save it in an object named train_score.
  • Score your model on the test set using .score() and save it in an object named test_score.
Hint 1
  • Are you using KNeighborsClassifier(n_neighbors=5)?
  • Are you using model.fit(X_train, y_train.to_numpy())?
  • Are you using model.score(X_train, y_train) to find the training score?
  • Are you using model.score(X_test, y_test) to find the test score?
Fully worked solution: