← 返回學院
A learner places a card on a two-axis trial chart while an instructor holds two alternatives across the table.
AI 知識核心2026年11月25日· 2 分鐘

Hyperparameter Search Under a Fixed Budget

A fixed trial budget forces a choice between grid search and random search. Worked counts show how each spends fits, how validation multiplies cost, and why scale and distribution shape matter more than any guarantee.

hyperparameter searchfixed trial budgetvalidation design

來源

完整課程摘要

A hyperparameter is a setting chosen before training, such as a regularization strength or a kernel width. Hyperparameter search means training many candidate configurations and keeping the one that validates best. Under a fixed budget, the question is not which search method is best in general but how to spend a limited number of fits.

Suppose the budget covers 24 candidate configurations. A grid over two parameters with four values each gives 16 configurations, using 16 of those slots or forcing a redesign. Random search instead samples 24 configurations, each drawn from a stated distribution. A common rule is to set the number of draws to the budget and sample continuous parameters from distributions such as log-uniform, so the interval from 0.001 to 0.01 has the same chance as the interval from 0.01 to 0.1. In scikit-learn terms, GridSearchCV evaluates every combination while RandomizedSearchCV samples a fixed number of candidates, and that number can be chosen independently of how many parameters you list.

Validation multiplies the count. With 24 configurations and 5-fold cross-validation, you fit 24 × 5 = 120 models. If you also refit the winner on the full training set, add 1 more fit, giving 121 fits. The held-out test set stays untouched until one final configuration is chosen, then evaluated once. Protecting the test set keeps its estimate honest, because repeated peeking turns it into another validation set. If the hard limit is 24 individual fits, four fivefold candidates and one final refit use 21. A fifth candidate would already require 25 validation fits.

Consider a case with two parameters. Parameter A ranges over 0.001 to 1.0 on a log scale, and parameter B is a discrete switch with three settings. A grid of 4 values of A times 3 values of B is 12 configurations. With a budget of 12 trials, random search would draw 12 points, but each draw must include a B setting, so four per setting is the expectation if the switch is sampled uniformly. The actual counts may differ. A grid guarantees coverage of all 12 cells, which helps when you suspect interactions. Random search helps when only one parameter matters, because the draws can test many distinct values of A even while B varies.

Neither method guarantees finding the best configuration. A grid can miss a narrow good region between its grid points, and random sampling can cluster by chance. A useful classroom task makes this visible. Give pairs a 3 × 4 grid drawn on paper and 12 tokens. Ask them to place tokens as a grid, then as random draws from a hat, and mark which cells receive attention. Have each pair write one sentence explaining where a narrow good region might be missed. Compare the sheets aloud. Compare the two reports. "Our grid never tested 0.03, so we cannot say it was bad." "Our random draws skipped one row entirely." This keeps reasoning public and shows that allocation choices, not slogans, shape what you learn.