6.1. Exercises
Regression Questions
Consider this toy dataset:

Question 1

Building a π-NN-Regressor
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 bring in this PokΓ©mon dataset again, but this time we are not going to be predicting a PokΓ©monβs capture rate (capture_rt) instead of its legendary classification.
We did the same process of cross validation and scoring as we did before but we obtain this plot:

This model didnβt end up having a clear best score when we hyperparameter tuned but in the end, we decided to use n_neighbors=12.
Letβs build a KNeighborsRegressor with this hyperparameter value and see how well your model does on the test data.
Tasks:
- Build a model using
KNeighborsRegressor()using the optimaln_neighbors. - Save this in an object named
model. - Fit your model on the objects
X_trainandy_train. - Evaluate the test score of the model using
.score()onX_testandy_testand save the values in an object namedtest_scorerounded to 4 decimal places.