Hyperparameter Optimization
Intermediate 13 min read Hyperparameter Optimization

Random Search

Fewer runs, better coverage — because most knobs don't matter

Random search samples hyperparameter combinations from distributions instead of an exhaustive lattice. With a fixed budget it covers the space better than an equally-sized grid, especially when only a few knobs matter.

random searchRandomizedSearchCVsamplingtuning budgetintrinsic dimension
Prerequisites: Grid Search
Before we start

What you will learn

  • Randomize over distributions, not lists
  • Explain why random search wins for low effective dimension
  • Grow budgets deliberately, not to the biggest grid
Introduction

What is this?

Random search draws candidate configurations by sampling each hyperparameter from a probability distribution (uniform on linear or log scale) and evaluates a fixed number of samples. Compared to a grid of the same size, random search explores more distinct values per knob — a famous result when only a few hyperparameters actually matter, which is the typical case.

Motivation

Why do you need it?

  • Grids spend most cells repeating similar values across an irrelevant knob.
  • With a budget of N fits and D knobs, grid gets ~N^(1/D) values per knob; random search independently samples all N values per knob.
  • Real tuning problems are low-dimensional in effect even when the space is wide.
  • It's parallel, reproducible (seeded), and gives clean uncertainty-free reasoning about budget use.
Think about it

Mental model

Imagine

Throwing darts vs. walking a floor plan cell-by-cell

Think of

Random vs grid search in a big room

Walking every 10-unit cell of a 100×100 floor uses enormous effort to cover each corridor once; darts thrown at random eventually land everywhere, and with equal darts you've scattered across every region rather than marching a lattice.

Mechanics

How it works

  • Define a distribution per knob: log-uniform for magnitudes, uniform/choice for discrete, integers for counts.
  • Sample N configs jointly from the product distribution (independent draws).
  • Evaluate each config with CV; keep the best mean score.
  • As budget grows, the empirical best approaches the true opt within the space.
  • Optionally refine around the best sample with a second tighter round.

Equal budget: grid vs random coverage.

Grid
Random
Sample
Evaluate
Best
Real world

In production

  • A gradient-boosting pipeline random-searches 60 configs (lr, depth, subsample, colsample) once, cheaply, instead of 6^4 = 1296 grid cells.
  • A neural-net trainer randomizes lr and weight-decay with a log-uniform sampler and 40 trials per tuning cycle.
  • Tuning-as-a-service systems sample the same pseudo-random seed for reproducibility audits.
Guidelines

Best practices

  • Use log-uniform for scale knobs (learning rate, strength) — equal chance per decade, not per linear step.
  • Fix the sampler seed and log the exact samples with the experiment.
  • Spend the budget in two waves: coarse global, then 2–3x denser around the promising region.
  • Add a no-op 'dummy knob' check: if it gets ranked top often, the score is noise-dominated.
Watch out

Common mistakes

  • Sampling uniform over [0, 1] for multiplicative knobs — a 0.001 learning rate gets sampled as often as 0.999.
  • Reusing the grid's value lists and sampling from them — you inherit the grid's poor spacing.
  • Randomly sampling seeds/batch sizes where sensitivity is fake, wasting budget.
  • Believing more samples always find better; at some point you're resampling the same plateau.
Root cause analysis

Common issues

Error
Random search 'finds' a worse config than the old default
Root cause

Budget too small or distributions miss the operational region

Fix

Doublt budget, check the sampled distribution covers the default region, and run a second focused round.

Error
Two seeds give very different winners
Root cause

Budget insufficient for the noise level

Fix

Increase number of samples or folds; treat winner selection as unstable until more budget.

When things break

Debugging tips

  • Plot score vs each knob from the logged samples to see which knobs actually move the metric.
  • If the top-10 configs scattered across unconnected regions, the response surface is noisy — increase folds, not samples.
  • Compare a 30-sample random run to a 30-cell grid run on the same budget; the winner is usually clear.
  • Ensure all samples are logged (config + fold scores) — the distribution of scores teaches more than the argmax.
Interviews

Interview checkpoint

Practice

Hands-on lab

Random vs Grid at the Same Budget
25 min · intermediate
In progress
Objectives
  • Run RandomizedSearchCV with log-uniform samplers
  • Compare same-budget grid and random outcomes
  • Demonstrate the low-dimensional-knob advantage

Random vs Grid at the Same Budget

25 min · intermediate

0/4 steps
0%
sandbox · Linux sandbox
$
Try these commands
Test yourself

Quick quiz

0/2
1

For a hyperparameter spanning 1e-4 to 1e-1, the right sampler is:

2

With the same number of evaluations, random search can cover each grid axis more densely.

Go deeper

Official documentation