Home Knowledge Base Random Search

Random Search is a hyperparameter optimization method that samples random combinations from specified distributions — proven by Bergstra & Bengio (2012) to be more efficient than Grid Search for most ML problems because it explores more unique values of important hyperparameters, can be stopped at any time with a "good enough" result, is embarrassingly parallel (every trial is independent), and requires no assumptions about the objective function landscape.

What Is Random Search?

Random Search vs Grid Search (Visual Explanation)

DimensionGrid Search (3×3 = 9 trials)Random Search (9 trials)
Learning RateTests 3 values: [0.001, 0.01, 0.1]Tests 9 unique values: [0.0023, 0.0071, 0.014, ...]
Weight DecayTests 3 values: [1e-4, 1e-3, 1e-2]Tests 9 unique values: [3.2e-4, 7.1e-4, ...]
Coverage of LR3 unique values ❌9 unique values ✓

If learning rate is the important parameter, Random Search explores 3× more of its range.

When to Use Which

MethodBest ForProsCons
Grid Search≤3 hyperparams, known good rangesExhaustive, reproducibleExponential cost, wastes time on unimportant params
Random Search3-10 hyperparams, broad rangesMore efficient, parallelizable, stoppableMay miss optimal region by chance
Bayesian OptimizationExpensive evaluations (hours per trial)Most sample-efficientSequential, harder to parallelize
Manual TuningExpert intuition, few key paramsVery fast for experienced practitionersNot systematic, hard to document

Python Implementation

from sklearn.model_selection import RandomizedSearchCV
from scipy.stats import loguniform, randint

param_distributions = {
    'learning_rate': loguniform(1e-4, 1e-1),
    'max_depth': randint(3, 12),
    'n_estimators': randint(100, 1000),
    'subsample': [0.6, 0.7, 0.8, 0.9, 1.0],
}

search = RandomizedSearchCV(
    model, param_distributions,
    n_iter=100, cv=5, scoring='accuracy',
    random_state=42, n_jobs=-1
)
search.fit(X_train, y_train)
print(f"Best: {search.best_params_}")

Practical Guidelines

BudgetStrategy
10-20 trialsRandom Search with broad ranges (exploration)
50-100 trialsRandom Search → narrow ranges → more Random Search
100+ trialsRandom Search for exploration → Bayesian for exploitation
UnlimitedStill start with Random Search to understand the landscape

Random Search is the practical default for hyperparameter optimization — providing better coverage of important hyperparameters than Grid Search at the same computational budget, supporting any distribution (continuous, discrete, categorical), and offering the unique advantages of being embarrassingly parallel (run on 100 GPUs simultaneously) and anytime-stoppable (the best result so far is always valid).

random searchsampletune

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.