How to find the best hyperparameters using Manual Search in Python

Hyperparameter tuning is one of the most important steps in machine learning. As the ML algorithms will not produce the highest accuracy out of the box. You need to tune their hyperparameters to achieve the best accuracy. You can follow any one of the below strategies to find the best parameters.

In this post, I have discussed about Manual search parameter tuning.

Manual Search is an ad-hoc approach to find the best values of hyperparameters for any machine learning algorithm. The idea is to first take big jumps in values and then small jumps to focus around a specific value which performed better.

For example, in the Random Forest algorithm, the n_estimators is the number of trees to grow. We can find the best value of this parameter by starting with big values like 100, 200, 500, 1000. and then once you know which one of them gave the best accuracy outcome you can choose to try values around that. e.g. if the accuracy was best around 500, then keep trying the values around it like 480, 490, 500, 510, 520, etc. Then choose whichever value gives the highest accuracy amongst it.

How will I know what values to try?

You can look at the sample values for each parameter in the function documentation using shift+tab after clicking on the function or the online sklearn documentation.

Mostly with some experience, you get a hang of good parameter values that work for most of the data.

In the below example you can try different values of n_estimators, criterion, and max_depth to get the highest accuracy value. Look for the weighted F1-Score value in the output. Whichever combination of parameters makes it highest. Choose those parameters as final.

Sample Output:

Hyper Parameter tuning of Random Forest using Manual Search
Hyper Parameter tuning of Random Forest using Manual Search

Author Details
Lead Data Scientist
Farukh is an innovator in solving industry problems using Artificial intelligence. His expertise is backed with 10 years of industry experience. Being a senior data scientist he is responsible for designing the AI/ML solution to provide maximum gains for the clients. As a thought leader, his focus is on solving the key business problems of the CPG Industry. He has worked across different domains like Telecom, Insurance, and Logistics. He has worked with global tech leaders including Infosys, IBM, and Persistent systems. His passion to teach inspired him to create this website!

Leave a Reply!

Your email address will not be published. Required fields are marked *