Choosing a Search Strategy for Model Hyperparameters
Machine LearningModel answerLast updated
Compare strategies for searching hyperparameters, from hand tuning to Bayesian and early-stopping methods, weighing cost, parallelism and sample efficiency.
You are training a model whose quality depends on several settings you choose before training, such as learning rate, regularization strength, tree depth, or batch size. Each training run is costly, and you have a limited compute budget.
Walk through the main strategies for finding good values for these settings. For each strategy, cover:
- The core idea, in plain terms.
- Strengths and weaknesses, including compute cost, how well it runs in parallel, and how efficiently it uses each trial.
- When you would pick it over the alternatives.
Your answer should include at least manual tuning, grid search, random search, and one model-based approach (such as Bayesian optimization) plus one adaptive / early-stopping approach (such as Successive Halving or Hyperband). Mention any practical pitfalls in how you evaluate candidate settings.
Hints
Hint 1
Treat the problem as minimizing an expensive, noisy validation score with no gradient available. Ask what each method does with the results of earlier trials.
Hint 2
Think about what happens when only one or two of the settings really matter. How many distinct values of those important settings does a grid test compared with the same number of random trials?
Hint 3
Bayesian methods spend extra effort choosing each trial, while early-stopping methods make each trial cheaper. Which is more sequential, and which assumes that early results predict final results?
Model answer
Easy Try it yourself first — then compare your approach, complexity and edge cases.
Framing
We want to minimize f(λ), the validation loss of a model trained with settings λ. f is expensive to evaluate, noisy, has no usable gradient, and the space often mixes continuous, integer and categorical values. Every method below is a black-box optimizer under those conditions. The comparison axes are: cost per trial, number of trials needed, parallelism, and robustness.
1. Manual tuning
Idea: An experienced practitioner picks values, reads learning curves and diagnostics (for example "loss diverges, so lower the learning rate"), and adjusts.
- Pros: Uses domain knowledge and signals automated methods ignore. It can be very sample-efficient in expert hands, and it is the best way to find sensible search ranges and a baseline.
- Cons: Hard to reproduce, biased by intuition, and it consumes human time. It does not scale past a handful of settings and is hard to parallelize.
- Use it: At the start, to get a working baseline and to define the ranges the automated methods will search.
2. Grid search
Idea: Choose a discrete list of values per setting and train on every combination. For example, 4 learning rates × 3 depths × 3 regularization values gives 36 runs.
- Pros: Simple, deterministic, reproducible, and trivially parallel.
- Cons: Cost grows as k^d for k values in d dimensions. It wastes budget when only some settings matter: in the 36-run example, only 4 distinct learning rates are ever tested. The optimum between grid points is missed.
- Use it: For one or two settings, or when the grid is tiny and cheap.
3. Random search
Idea: Sample each setting independently from a distribution (log-uniform for scale-like settings such as learning rate and weight decay), train, and keep the best.
Why it usually beats grid: Most problems have low effective dimensionality, meaning a few settings drive most of the performance. With N random trials you test N distinct values of every important setting, whereas a grid gives only about N^(1/d). There is also a clean budget argument: the chance that at least one of n trials lands in the best 5% of the space is 1 − 0.95^n, which is about 95% at n = 60, regardless of dimension.
- Pros: Embarrassingly parallel, can be stopped at any time, easy to extend with more trials, and a strong baseline.
- Cons: It ignores what earlier trials revealed, so it is wasteful when each trial is expensive.
- Use it: As the default when you have moderate budget and many workers.
4. Bayesian optimization
Idea: Fit a probabilistic surrogate of f from the (λ, score) pairs seen so far. An acquisition function (Expected Improvement, Upper/Lower Confidence Bound) picks the next λ by balancing exploitation (good predicted score) against exploration (high uncertainty). Evaluate, update, repeat.
Surrogates:
-
Gaussian processes: good below roughly 20 continuous dimensions, with cubic cost in the number of observations.
-
Tree-structured Parzen Estimators (Hyperopt, Optuna): model p(λ | good) versus p(λ | bad); handle categorical and conditional spaces well.
-
Random forests (SMAC).
-
Pros: Far fewer trials than random search when each run takes hours.
-
Cons: Inherently sequential. Parallel versions (batch acquisition, "constant liar", Thompson sampling) lose some efficiency. Surrogate overhead grows with data, and GPs struggle with high dimension and many categorical values. Noisy objectives can mislead it, and the advantage over random search shrinks with large budgets.
-
Use it: When trials are expensive, the budget is a few dozen to a few hundred runs, and parallelism is limited.
5. Adaptive / multi-fidelity methods
Idea: Do not give bad configurations a full budget. Evaluate many configurations at low fidelity (few epochs, a data subset, a smaller model) and promote only the promising ones.
-
Successive Halving: Start n configurations with budget r. Keep the top 1/η, multiply their budget by η, and repeat.
-
Hyperband: Runs several Successive Halving brackets with different trade-offs between number of configurations and starting budget, hedging against not knowing how aggressively to prune.
-
ASHA: The asynchronous version. A configuration is promoted as soon as it ranks in the top 1/η of its rung, so there is no waiting on stragglers. It scales to many workers.
-
BOHB: Hyperband with model-based (TPE-style) sampling instead of random sampling.
-
Pros: Often about an order of magnitude cheaper than full-budget search, and ASHA parallelizes well.
-
Cons: Assumes early rankings predict final rankings. It is biased against slow starters (small learning rates, heavy regularization). The training loop must report intermediate metrics and support checkpoints.
-
Use it: For deep learning with many workers and long training runs.
6. Population-Based Training
Idea: Train a population in parallel. Periodically, weak members copy the weights and settings of strong ones (exploit) and then perturb the settings (explore), for example scaling the learning rate by 0.8 or 1.2.
- Pros: Learns schedules rather than fixed values, and one population-sized budget yields a tuned model. Popular in reinforcement learning and large networks.
- Cons: Needs many concurrent workers, the result is a path-dependent schedule that is hard to reproduce, and greedy selection can collapse diversity.
7. Others
Evolutionary methods and CMA-ES suit rugged or mixed spaces but need many samples. Gradient-based hyperparameter tuning is efficient but applies only to continuous settings and needs differentiable setups.
Practical guidance and common mistakes
- Evaluation hygiene: Tune on a validation set (or cross-validation) and report final performance on a separate untouched test set. Tuning against the test set leaks information and inflates results.
- Search space: Use log scales for rates and regularization, keep ranges wide at first, and check that the best values are not sitting on a boundary.
- Noise: Seed variance can exceed small differences between configurations. Repeat top candidates with several seeds before trusting a winner.
- Leakage inside the pipeline: Fit preprocessing (scalers, encoders) inside each training fold, not on all the data.
- Recommended workflow: Start manually to get a baseline and ranges, run random search or a Hyperband/ASHA variant for broad coverage, and switch to Bayesian optimization (or BOHB) if runs are expensive and parallelism is limited. Finally, retrain the best configuration on train plus validation data and evaluate once on the test set.
Summary table
| Method | Parallelism | Trials needed | Main weakness |
|---|---|---|---|
| Manual | Poor | Few (expert) | Not reproducible |
| Grid | Excellent | Exponential | Curse of dimensionality |
| Random | Excellent | Moderate | Ignores history |
| Bayesian | Limited | Low | Sequential, overhead |
| Hyperband/ASHA | Excellent | Cheap per trial | Early-ranking bias |
| PBT | Needs a population | One population run | Hard to reproduce |