Bayesian Optimization
Choosing the next trial intelligently
Bayesian optimization builds a surrogate model of the score surface and picks the next config to maximize information per trial. It squeezes the most from expensive evaluations—ideal when each fit costs minutes or hours.
What you will learn
- Describe the surrogate + acquisition loop
- Explain exploration-exploitation in sampling
- Use Optuna-style Bayesian search on expensive models
What is this?
Bayesian optimization frames tuning as sequential decision making. It keeps a surrogate model — typically a Gaussian process or a Tree-structured Parzen Estimator (TPE) — that predicts score as a function of configuration, including uncertainty. An acquisition function (expected improvement, UCB, EI) scores candidate next configs by balancing 'where the surrogate says the best config lives' (exploitation) against 'where we're most uncertain' (exploration), and the winner is evaluated, folded back into the surrogate, and the loop repeats.
Why do you need it?
- Expensive models (deep nets, big GBDTs) can't afford thousands of trials — Bayesians make each one count.
- Correlated knobs are exploited naturally (learning rate and depth interact).
- Uncertainty is explicit: you know when you're guessing vs done.
- It typically beats random search 2–5× in trials-to-optimum on smooth surfaces.
Mental model
A treasure hunt with noise on the metal detector
Bayesian optimization
You don't grid-search the whole beach. You map readings (surrogate), pick the most promising-but-uncertain spot (acquisition), dig there, update your mental map, and repeat — exploring new beaches only when signal is thin.
How it works
- Evaluate a handful of random-start configs to seed surrogate uncertainty.
- Fit the surrogate: score ≈ f(config) with mean and variance predictions.
- Maximize the acquisition function (e.g., expected improvement) over the space to pick the next config.
- Evaluate that config (CV or validation), record score, add to history.
- Refit the surrogate and repeat until the budget or a tolerance bound is hit.
The Bayesian optimization loop.
In production
- A deep-learning team tunes lr, batch size, warmup and weight decay with Optuna — ~60 trials instead of grid's ~1,300.
- An AutoML service uses TPE sampling because tree-based surrogates handle mixed categorical/continuous spaces.
- A recurring monthly retrain never needs a full search: the warm-started surrogate re-tunes around the previous optimum.
Best practices
- Start with the previous best config in the seed set — warm-starting beats cold search.
- Bound the space to plausible regions; wide spaces just slow surrogate refinement.
- Let the surrogate see log-transformed knobs so distances make sense (learning rate magnitudes).
- Add a pruning racing layer (Hyperband-style) when evaluations are trainable iteratively.
Common mistakes
- Using Bayesian search on cheap models where random/grid would finish first — overhead dwarfs savings.
- Forgetting to transform log-scale knobs, so the surrogate fits a much harder landscape.
- Over-trusting EI with a tiny surrogate: sample variance collapses too fast and it exploits a false peak.
- Interpreting the surrogate's predicted best as guaranteed — it's predicted, not measured.
Common issues
Bayesian search hits a plateau lower than a known random-search resultSurrogate exploited a spurious early peak; exploration didn't rescue
Lower exploration temperature (increase EI exploration weight), re-seed with more random starts, and verify ranges.
Optimization takes longer than the model trainsSurrogate refit overhead dominates the cheap evaluation
Use a cheaper surrogate (TPE over GP), or just use random search — the model is cheap enough.
Debugging tips
- Plot history of observed scores — each trial should mostly land near-or-better than the previous best.
- If acquisition keeps picking boundary values, your ranges are too tight; widen and re-seed.
- Check surrogate predictions vs actuals on a holdout slice of trials to detect surrogate pathology.
- Keep a fixed random-search comparison: if Bayesian isn't beating it, the surface may be noise-dominated — switch budget to folds.
Interview checkpoint
Hands-on lab
- Define a tuning study with log-uniform knobs
- Let Optuna's TPE pick trials sequentially
- Beat a random-search baseline at equal budget
Optuna: Fewer Trials, Same Winner
30 min · advanced
Quick quiz
The acquisition function balances:
Bayesian optimization always beats random search.