5.1. Exercises
Exhaustive or Randomized Grid Search
Hyperparameter Quick Questions
Using Automated Hyperparameter Optimization in Action!
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.
Now that we have built a pipeline in the last interactive exercises, letโs pair that with grid search to optimize our hyperparameters.
Tasks:
- Using the pipeline provided, create a grid of parameters to search over named
param_grid. Search over the values 1, 5, 10, 20, 30, 40, and 50 for the hyperparametern_neighborsand โuniformโ and โdistanceโ for the hyperparameterweights(make sure to call them appropriately). - Use
GridSearchCVto hyper-parameter tune using cross-validate equal to 10 folds. Make sure to specify the argumentsverbose=1andn_jobs=-1. Name the objectgrid_search. - Find the best hyperparameter values and save them in an object named
best_hyperparams. Make sure to print these results. - Lastly, score your model on the test set and save your results in an object named
bb_test_score.