-
Book Overview & Buying
-
Table Of Contents
Hyperparameter Tuning with Python
By :
Implementing Random Search in Optuna is very similar to implementing TPE in Optuna. We can just follow a similar procedure to the preceding section and change the sampler parameter in the optimize() method in step 2. The following code shows you how to do that:
study = optuna.create_study(direction='maximize',
sampler=optuna.samplers.RandomSampler(seed=0))
Using the exact same data, preprocessing steps, hyperparameter space, and objective function, we get around 0.548 in the F1-score evaluated in the validation data. We also get a dictionary consisting of the best set of hyperparameters as follows:
{'num_layers': 0,'optimizer': 'Adam','adam_lr': 0.05075826567070766,'epoch': 50}
After the model is trained with full data using the best set of hyperparameters, we get around 0.596 in F1-score when we test the final neural network model trained on the test data. Notice that although we...