Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hyperparameter Tuning with Python

You're reading from  Hyperparameter Tuning with Python

Product type Book
Published in Jul 2022
Publisher Packt
ISBN-13 9781803235875
Pages 306 pages
Edition 1st Edition
Languages
Author (1):
Louis Owen Louis Owen
Profile icon Louis Owen
Toc

Table of Contents (19) Chapters close

Preface 1. Section 1:The Methods
2. Chapter 1: Evaluating Machine Learning Models 3. Chapter 2: Introducing Hyperparameter Tuning 4. Chapter 3: Exploring Exhaustive Search 5. Chapter 4: Exploring Bayesian Optimization 6. Chapter 5: Exploring Heuristic Search 7. Chapter 6: Exploring Multi-Fidelity Optimization 8. Section 2:The Implementation
9. Chapter 7: Hyperparameter Tuning via Scikit 10. Chapter 8: Hyperparameter Tuning via Hyperopt 11. Chapter 9: Hyperparameter Tuning via Optuna 12. Chapter 10: Advanced Hyperparameter Tuning with DEAP and Microsoft NNI 13. Section 3:Putting Things into Practice
14. Chapter 11: Understanding the Hyperparameters of Popular Algorithms 15. Chapter 12: Introducing Hyperparameter Tuning Decision Map 16. Chapter 13: Tracking Hyperparameter Tuning Experiments 17. Chapter 14: Conclusions and Next Steps 18. Other Books You May Enjoy

Implementing Random Search

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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime