1. Learn
  2. /
  3. Courses
  4. /
  5. Hyperparameter Tuning in Python

Connected

Exercise

Grid and Random Search Side by Side

Visualizing the search space of random and grid search together allows you to easily see the coverage that each technique has and therefore brings to life their specific advantages and disadvantages.

In this exercise, you will sample hyperparameter combinations in a grid search way as well as a random search way, then plot these to see the difference.

You will have available:

  • combinations_list which is a list of combinations of learn_rate and min_samples_leaf for this algorithm
  • The function visualize_search() which will make your hyperparameter combinations into X and Y coordinates and plot both grid and random search combinations on the same graph. It takes as input two lists of hyperparameter combinations.

If you wish to view the visualize_search() function definition, you can run this code:

import inspect
print(inspect.getsource(visualize_search))

Instructions 1/4

undefined XP
    1
    2
    3
    4
  • Sample (by slicing) 300 hyperparameter combinations for a grid search from combinations_list into two lists and print the result.