5. Fine-Tune Your Model

Say our best performing model was the RandomForestRegressor. This is a model that has many input hyperparameters that can be tweaked for improving performance. For example, we could have a forest with 100 or 1000 trees, or we could use 10 or 50 features during random selection. What are the best values for these hyperparameters to pass as input to the model for training?

Should we fiddle with all the possible values manually and then compare results to find the best combination of hyperparameters? This would be really tedious work, and we would end up exploring only a few possible combinations.

Luckily, we can use Scikit-learn’s GridSearchCV to do this tedious search work for us. All we need to do is tell it which hyperparameters we would like to explore and which values to try out, and it will evaluate all the possible combinations of hyperparameter values, using cross-validation.

For example, let’s see how to search for the best combination of hyperparameter values for the RandomForestRegressor:

Get hands-on with 1200+ tech skills courses.