Hyperparameter Tuning with Python by Louis Owen
Author:Louis Owen
Language: eng
Format: epub
Publisher: Packt Publishing Pvt Ltd
Published: 2022-07-28T00:00:00+00:00
Implementing Coarse-to-Fine Search
Coarse-to-Fine Search (CFS) is part of the Multi-Fidelity Optimization group that utilizes Grid Search and/or Random Search during the hyperparameter tuning process (see Chapter 6, Exploring Multi-Fidelity Optimization). Although CFS is not implemented directly in the sklearn package, you can find the implemented custom class, CoarseToFineSearchCV, in the repo mentioned in the Technical Requirements section.
Letâs use the same example and hyperparameter space as in the Implementing Random Search section, to see how CoarseToFineSearchCV works in practice. Note that this implementation of CFS only utilizes Random Search and uses the top N percentiles scheme to define the promising subspace in each iteration, similar to the example shown in Chapter 6. However, you can edit the code based on your own preference since CFS is a very simple method with customizable modules.
The following code shows you how to perform CFS with the CoarseToFineSearchCV class. It is worth noting that this class has very similar parameters to the RandomizedSearchCV class, with several additional parameters. The random_iters parameter controls the number of iterations for each random search trial, top_n_percentile controls the N value within the top N percentiles promising subspace definition (see Chapter 6), n_iter defines the number of CFS iterations to be performed, and continuous_hyperparams stores the list of continuous hyperparameters in the predefined space.
Initiate the CoarseToFineSearchCV class:
clf = CoarseToFineSearchCV(pipe, hyperparameter_space,
random_iters=25, top_n_percentile=50, n_iter=10,
continuous_hyperparams=['model__min_samples_split'],
random_state=0, scoring='f1', cv=5,
n_jobs=-1, refit=True)
Run the CoarseToFineSearchCV class:
clf.fit(X_train_full, y_train)
Print the best set of hyperparameters:
print(clf.best_params_, clf.best_score_)
Evaluate the final trained model on the test data:
y_pred = clf.predict(X_test_full)
print(f1_score(y_test, y_pred))
Based on the preceding code, we get around 0.561 for the F1-score when testing our final trained RF model with the best set of hyperparameters on the test set. The best set of hyperparameters is {âmodel__class_weightâ: âbalanced_subsampleâ, âmodel__criterionâ: âentropyâ, âmodel__min_samples_splitâ: 0.005867409821769845, âmodel__n_estimatorsâ: 106} with an objective function score of 0.560.
In this section, we have learned how to implement CFS using a custom class on top of sklearn through the CoarseToFineSearchCV class. In the next section, we will learn how to perform SH with sklearn.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
AI & Machine Learning | Bioinformatics |
Computer Simulation | Cybernetics |
Human-Computer Interaction | Information Theory |
Robotics | Systems Analysis & Design |
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8293)
Test-Driven Development with Java by Alan Mellor(6669)
Data Augmentation with Python by Duc Haba(6573)
Principles of Data Fabric by Sonia Mezzetta(6335)
Learn Blender Simulations the Right Way by Stephen Pearson(6222)
Microservices with Spring Boot 3 and Spring Cloud by Magnus Larsson(6093)
Hadoop in Practice by Alex Holmes(5958)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5806)
RPA Solution Architect's Handbook by Sachin Sahgal(5488)
Big Data Analysis with Python by Ivan Marin(5333)
The Infinite Retina by Robert Scoble Irena Cronin(5188)
Life 3.0: Being Human in the Age of Artificial Intelligence by Tegmark Max(5140)
Pretrain Vision and Large Language Models in Python by Emily Webber(4294)
Infrastructure as Code for Beginners by Russ McKendrick(4055)
Functional Programming in JavaScript by Mantyla Dan(4037)
The Age of Surveillance Capitalism by Shoshana Zuboff(3943)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3769)
Embracing Microservices Design by Ovais Mehboob Ahmed Khan Nabil Siddiqui and Timothy Oleson(3572)
Applied Machine Learning for Healthcare and Life Sciences Using AWS by Ujjwal Ratan(3547)
