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 Particle Swarm Optimization

PSO is also one of the variants of the Heuristic Search hyperparameter tuning group (see Chapter 5) that can be implemented by the DEAP package. We’ll still use the same example as in the previous section to see how we can implement PSO using the DEAP package.

The following code shows how to implement PSO with the DEAP package. You can find the more detailed code in the GitHub repository mentioned in the Technical requirements section:

  1. Define the PSO parameters and type classes through the creator.create() module:
    N = 50 #swarm size
    w = 0.5 #inertia weight coefficient
    c1 = 0.3 #cognitive coefficient
    c2 = 0.5 #social coefficient
    num_trials = 15 #number of trials

Fix the seed for reproducibility:

import random
random.seed(1)

Define the type of our fitness function. Here, we are working with a maximization problem and a single objective function, which is why we set weights=(1.0,):

from deap import creator, base...
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