Random Search vs Grid Search
Searching for good hyperparameters by trying every combination on a fixed grid sounds thorough, but sampling combinations at random from the same ranges usually finds a better setting for the same amount of compute.
Prerequisites: Hyperparameters vs Parameters, Hyperparameter Tuning
Choosing hyperparameters like learning rate and regularization strength means searching over combinations you can't evaluate without actually training the model each time — an expensive way to explore. Grid search picks a handful of values for each hyperparameter and tries every combination: a natural-feeling, exhaustive-looking approach. Random search instead samples hyperparameter combinations randomly from the same ranges, the same number of times. The surprising finding, both theoretical and empirical, is that random search usually finds a better setting for the same evaluation budget — because most hyperparameters don't matter nearly as much as one or two of them do, and grid search wastes its budget spreading evenly across all of them.
The analogy: searching for a signal along the important street
Imagine two hyperparameters as two streets crossing at right angles, and somewhere along the north-south street (and nowhere in particular along the east-west one) is where a hidden signal is strongest. A grid search with 3 values per street tests only 3 distinct positions along the important north-south street, no matter how many points you add to the unimportant east-west one — because every one of the grid's points shares those same 3 north-south values, just repeated at different east-west positions. A random search with the same total number of tries places its points at many different positions along both streets, so it tests far more distinct positions along whichever street actually matters — without needing to know in advance which one that is.
Why the effective resolution differs
Suppose a search budget allows total trials over hyperparameters, and (as is common in practice) only of those hyperparameters actually affect performance much. Grid search with trials and dimensions typically uses roughly distinct values per dimension — so as grows, the number of distinct values tested per important dimension shrinks fast. Random search, by contrast, always tests distinct values along every dimension, important or not, because each trial's coordinate along each axis is drawn independently:
In words: grid search's resolution along any one axis degrades as more hyperparameters are added, because the same trial budget has to be spread across every combination; random search's resolution along any one axis stays at the full trial count regardless of how many other hyperparameters are being searched alongside it.
Worked example 1: grid search's shrinking resolution
Budget of trials, searching hyperparameters with a grid. An even grid uses values per hyperparameter ( combinations). If only 1 of those 3 hyperparameters actually matters, grid search has only tested 4 distinct values of the one that matters — the other 48 combinations tested three different, irrelevant hyperparameters at those same 4 values.
Worked example 2: random search's full resolution
Same budget, random trials over the same 3 hyperparameters, each drawn independently from its range. Along the one hyperparameter that matters, random search has effectively tested 64 distinct values (with high probability, since continuous draws rarely repeat exactly) — sixteen times finer resolution along the dimension that actually determines performance, for the identical total compute budget of 64 trials.
Choosing what shape to sample each hyperparameter from — uniform, log-uniform, normal — is itself part of designing a search; the explorer above shows how a distribution's shape controls where samples concentrate, the same choice you make when deciding how to draw random hyperparameter values.
What this means in practice
Random search is now a common default baseline for hyperparameter tuning specifically because it's simple, parallelizes trivially (every trial is independent), and empirically tends to beat grid search at the same budget, especially once you're searching more than two or three hyperparameters at once. It is itself often outperformed by more adaptive methods like Bayesian optimization or successive halving, but as a baseline it is a large step up from grid search at essentially no extra implementation cost.
Grid search spends its fixed trial budget spreading evenly across every hyperparameter combination, which wastes resolution on unimportant dimensions; random search tests as many distinct values along every dimension as it has trials, regardless of how many other hyperparameters share the budget.
Practice
- With a budget of 100 trials over 4 hyperparameters, how many distinct values per hyperparameter does an even grid test?
- Why does random search's per-axis resolution not degrade as more hyperparameters are added to the search?
- Name one hyperparameter search scenario where a small, evenly-spaced grid might actually be preferable.
It's tempting to assume grid search is strictly the more "thorough" choice because it covers every combination. That thoroughness is exactly the problem: with a fixed budget, covering every combination of unimportant hyperparameters means sacrificing resolution on the one or two that actually matter, since nobody knows in advance which hyperparameters those will be. Random search's willingness to leave some combinations untested is what lets it concentrate resolution wherever it turns out to matter.
Related concepts
Practice in interviews
Further reading
- Bergstra & Bengio, Random Search for Hyper-Parameter Optimization, JMLR (2012)