skip to content

Hyperparameter Search

Searching a configuration space on a budget — exhaustive grids, random draws, and surrogate or bandit methods that spend trials near the good region. Interviewers ask what you would tune first.

on this pageshow

explore

questions

9

How does Bayesian hyperparameter search pick the next configuration to evaluate?

level: middleimportance: must knowfreq 66%

answer

  1. a cheap stand-in for the expensive training run
  2. belief, decision rule, ground truth
  3. posterior mean and posterior uncertainty
  4. expected gain over the best score so far
  5. uncertainty raises the score, not lowers it

basics

~20 s

Bayesian search fits a probabilistic surrogate mapping hyperparameters to validation score from the trials run so far, then evaluates whichever configuration maximises an acquisition function such as expected improvement, which rewards both high predicted score and high uncertainty.

solid answer

~50 s

It keeps a probabilistic model of the objective instead of sampling blindly. After each trial you have pairs of (configuration, validation score); a surrogate is fitted to those pairs and returns, for any candidate configuration, both a predicted score and an uncertainty. An acquisition function turns that pair of numbers into a single ranking. The usual one is expected improvement: `EI(x) = E[max(f(x) - f_best, 0)]` under the surrogate's posterior, where `f_best` is the best score observed so far. EI is high where the predicted score is good and also where the surrogate is unsure, so the search naturally alternates between refining a promising basin and probing unexplored regions. You then train the real model at the arg-max of EI, add the result to the history, refit, and repeat. The surrogate is cheap; the real evaluation is not, which is the whole reason the loop pays for itself.

go deeper

for a junior

Be able to say that the search learns from earlier trials instead of ignoring them, and that it keeps a cheap model of which settings look promising before spending another full training run.

for a middle

Explain the three moving parts in your own words: a surrogate fitted to (configuration, score) pairs, an acquisition function that ranks candidates, and the real evaluation that updates the history. Expect to define expected improvement.

for a senior

Show you know when the machinery fails to pay: noisy cross-validated scores, very high-dimensional or conditional spaces, and cheap evaluations where the sequential refit is the bottleneck. Say what you would change in each case.

for a principal

Own the framing that search-space design usually beats search-algorithm choice. Be ready to argue how much engineering complexity a surrogate-based search justifies for a given team and evaluation cost.

## The problem Tuning hyperparameters means optimising a function `f(x)` where `x` is a configuration (learning rate, depth, regularisation strength, number of trees) and `f(x)` is the validation score you get after training a model with that configuration. This function is **black-box** (no formula, no gradient), **expensive** (one evaluation is a full training run, possibly cross-validated), and **noisy** (a different fold split or seed gives a slightly different score). Sampling configurations independently ignores everything the previous trials told you. Bayesian optimisation is the family of methods that reuses that information. ## The loop 1. Evaluate a handful of configurations to get an initial history `D = {(x_1, y_1), ..., (x_n, y_n)}`. 2. Fit a **surrogate**: a cheap probabilistic model of `f` given `D`. 3. Score every candidate `x` with an **acquisition function** built from the surrogate's beliefs. 4. Train the real model at the best-scoring candidate, append `(x, y)` to `D`, and go back to step 2. The surrogate costs milliseconds to fit and query; the real evaluation costs minutes to hours. That asymmetry is what makes the extra machinery worth it. ## Surrogates A **Gaussian process** treats `f` as a draw from a distribution over smooth functions. Given the observed points it returns, at any new `x`, a posterior mean `mu(x)` and a posterior standard deviation `sigma(x)`. Near observed points `sigma` is small; far from them it is large. Gaussian processes are excellent on a handful of continuous, roughly smooth knobs, and awkward when the space is high-dimensional, mostly discrete, or conditional (a knob that only exists when another knob takes a particular value). Fitting cost also grows steeply with the number of observations. A **tree-structured Parzen estimator** flips the modelling around. It splits the history into a good group and a bad group at some quantile of the observed scores, fits a density `l(x)` over the good configurations and a density `g(x)` over the rest, and prefers configurations that maximise the ratio `l(x) / g(x)` — points that look like the winners and unlike the losers. Under its assumptions that ratio is a monotone stand-in for expected improvement. It handles discrete, categorical and conditional parameters comfortably and scales better in the number of trials, at the price of modelling each dimension's density rather than the full joint interaction. ## Expected improvement For a maximisation problem with best-so-far `f_best`, expected improvement is `EI(x) = E[max(f(x) - f_best, 0)]`, the expected amount by which evaluating `x` would beat the incumbent, averaged over the surrogate's posterior at `x`. Two very different configurations can score highly: - one whose predicted mean is a little above `f_best` with small uncertainty (exploitation), and - one whose predicted mean is mediocre but whose uncertainty is wide, so the upper tail of its posterior still reaches well past `f_best` (exploration). That is the whole exploration/exploitation balance, and it falls out of the definition rather than being bolted on with a tuning knob. A pure greedy rule ("evaluate the highest predicted mean") would lock onto the first decent basin and never look elsewhere. Other acquisition rules exist — upper confidence bound `mu(x) + kappa * sigma(x)`, which exposes the balance as an explicit `kappa`, or probability of improvement, which is greedier than EI because it counts *any* improvement equally rather than weighting by how large it is. ## When it earns its keep, and when it does not It pays off when each evaluation is expensive and your total budget is tens of trials rather than thousands — exactly the regime where using history matters. It struggles when: the space is very high-dimensional (the surrogate needs data to be informative, and there is never enough); the scores are very noisy, so the surrogate chases lucky folds instead of real structure (repeated cross-validation or a noise-aware surrogate helps); or evaluations are so cheap that the sequential surrogate refit and the inability to saturate many workers cost more than they save. One subtlety worth naming: the acquisition function is itself optimised, usually by dense sampling plus local refinement over the configuration space. That inner optimisation is cheap because it only queries the surrogate, never the real model. ## What interviewers listen for A clean separation of the three pieces — surrogate (belief), acquisition (decision rule), real evaluation (ground truth) — and an explanation of why uncertainty is *rewarded* rather than penalised. Candidates who describe Bayesian search as "random sampling but smarter" without naming a surrogate have not understood it.

  • Two regions have the same predicted score but one has never been sampled. Which does expected improvement pick?
    The unsampled one. With equal predicted means, the region with wider posterior uncertainty has more probability mass above the current best, so its expected improvement is larger. That is exploration emerging from the definition rather than from a separate exploration parameter.
  • How does a tree-Parzen surrogate differ from a Gaussian process?
    A Gaussian process models the score surface directly and returns a mean and variance at any point, which suits a few smooth continuous knobs. A tree-Parzen estimator instead models the density of good configurations against the density of bad ones and prefers a high ratio. It copes far better with discrete, categorical and conditional parameters and with larger trial counts.
  • Why is noisy validation scoring a problem for the surrogate?
    The surrogate treats each observed score as evidence about the underlying objective. If a score swings by a point just from fold assignment, the surrogate fits the noise, expected improvement chases a lucky fold, and the search converges on a configuration that was never really best. Repeated or stratified cross-validation, more folds, or a surrogate with an explicit noise term all reduce this.

It is prospecting with a geological map you redraw after every drill hole. You drill where the map says gold is likely, but also where the map is simply blank, because blank means the payoff could be anything.

saying these in an interview costs you the question

  • Describes it as random sampling with no surrogate model
  • Says the acquisition function always picks the highest predicted score
  • Thinks the surrogate replaces training the real model
  • Treats posterior uncertainty as a reason to avoid a region
  • Claims it beats simpler search at any dimensionality or budget

context

open as a page

Why does random search over hyperparameters usually beat an exhaustive grid on the same budget?

level: middleimportance: must knowfreq 78%

basics

~20 s

At the same trial count, random search tries a fresh value of every hyperparameter in every trial, while a grid reuses the same few values per axis. When only two or three hyperparameters matter, random search resolves those axes far more finely.

open as a page

How do successive halving and Hyperband allocate a fixed tuning budget?

level: middleimportance: should knowfreq 44%

basics

~20 s

Successive halving trains many configurations on a small budget, keeps the best fraction, multiplies the budget, and repeats. Hyperband runs several such brackets with different starting aggressiveness, hedging against early stopping that discards a slow starter.

open as a page

Why sample a learning rate log-uniformly on [1e-4, 1e-1] instead of uniformly?

level: middleimportance: should knowfreq 45%

basics

~20 s

Because the interesting values span decades, not units. A uniform draw on that interval puts about 90 percent of the trials above 0.01 and almost none near 0.0001, whereas a log-uniform draw gives each decade an equal share of the budget.

open as a page

How do you keep successive halving from cutting a configuration that only wins at full budget?

level: seniorimportance: should knowfreq 36%

basics

~20 s

Successive halving assumes the ranking at a small budget matches the ranking at full budget. When it does not, raise the first rung's budget, cut less aggressively, run less aggressive Hyperband brackets, and validate the proxy's rank correlation first.

open as a page

Would you choose Bayesian search or Hyperband for a four-hour run on 16 parallel workers?

level: principalimportance: should knowfreq 30%

basics

~20 s

Prefer Hyperband when a cheap fidelity ranks configurations like full training and workers are plentiful; prefer Bayesian search when evaluations are expensive and few. Hybrids sample configurations with a surrogate and schedule them with brackets.

open as a page

With a fixed 60-trial budget and six hyperparameters, how do you decide what to search?

level: principalimportance: should knowfreq 38%

basics

~20 s

Start from the compute you have, not the size of the space. Fix the hyperparameters that rarely matter at defaults and give the whole budget to the two or three that plausibly move the score.

open as a page

Should a weekly hyperparameter search be warm-started from last week's best configuration?

level: seniorimportance: nice to knowfreq 26%

basics

~20 s

Warm-start by seeding the surrogate with past trials, not by trusting last week's winner. Old scores do not transfer to new data, so re-evaluate the incumbent, keep some random exploration, and cold-start periodically to catch a moved optimum.

open as a page

How do you search a space where an RBF kernel has a gamma but a linear kernel has none?

level: seniorimportance: nice to knowfreq 25%

basics

~20 s

Treat the space as conditional rather than rectangular: sample the kernel first, and only draw the width parameter when the kernel that uses it was chosen. A flat cross-product instead fits the same linear model many times over.

open as a page