Implementing Random Search
Random Search is one of the variants of the Exhaustive Search hyperparameter tuning group (see Chapter 3) that the NNI package can implement. Let’s use the same data, pipeline, and hyperparameter space as in the example in the previous section to show you how to implement Random Search with NNI using pure Python code.
The following code shows how to implement Random Search with the NNI package. Here, we’ll use pure Python code instead of using nnictl
as in the previous section. You can find the more detailed code in the GitHub repository mentioned in the Technical requirements section:
- Prepare the model to be tuned in a script. We’ll use the same
model.py
script as in the previous section. - Define the hyperparameter space in the form of a Python dictionary:
hyperparameter_space = { 'model__n_estimators': {'_type': 'randint', '_value': [5, 200]}, ...