Hyperparameter Tuning

Grid, random and Bayesian search with tools like Optuna, plus how to tune efficiently without overfitting the validation set.

Intermediate · about 5 hours · difficulty 3/5

Learn first: Bias, Variance and Generalization, Gradient Boosting with XGBoost and LightGBM

Hyperparameters are settings you choose rather than learn (tree depth, learning rate, regularization strength). Systematic tuning often gives a solid gain, but beyond a point it offers less than better data or features.

Methods

  • Grid search: exhaustive, fine for two or three parameters.
  • Random search: usually more efficient than grid, because only a few parameters matter much.
  • Bayesian optimization (Optuna, scikit-optimize): builds a model of the score surface and samples promising regions.
  • Successive halving / Hyperband: kill bad configurations early to save compute.

Practice

  • Search learning rates and regularization on a log scale.
  • Start from library defaults and published good ranges; tune the most important parameters first.
  • Tune inside cross-validation with a pipeline, then evaluate the final choice on the untouched test set.
  • Log every trial (value, parameters, time) so you can see which parameters matter.

Pitfalls

Running thousands of trials against one small validation split effectively trains on it. Watch for improvements smaller than fold-to-fold noise.

Good enough to move on when you can run an Optuna study on a gradient boosting model with cross-validation and explain the parameter importance plot.

Key concepts

  • Grid search
  • Random search
  • Bayesian optimization with Optuna
  • Successive halving
  • Log-scale search spaces

Mini project

Tune a LightGBM model on the Kaggle House Prices data with both RandomizedSearchCV and an Optuna study of equal budget, and compare best scores and wall-clock time.

Check yourself

Why does random search often beat grid search with the same number of trials?

Free resources