Skip to main content
XenonStack
Hyperparameter Tuning: Grid and Random Search Guide
J
K
N
O
R
X
Y
Z

XenonStack Glossary Hyperparameter Tuning: Grid and Random Search Guide

Key takeaway

  • Hyperparameter tuning finds the settings a model cannot learn itself. Compare grid search, random search and successive halving, and see where to start.

Hyperparameter tuning is the process of searching for the settings that are not learned by a model during training, such as the kernel or regularisation strength, so that the model performs better on unseen data. It is usually done by scoring candidate settings with cross-validation.

This page is for data scientists and technology leaders who want to compare the main search methods, avoid common mistakes and understand how tuning fits into the work of AI agents and models.

What is hyperparameter tuning?

The scikit-learn tuning guide defines hyperparameters as parameters that are not directly learnt within estimators. Typical examples include C, kernel and gamma for a support vector classifier, or alpha for Lasso. In a library such as scikit-learn they are passed as arguments when the model is created.

Two-column diagram. Search methods: grid search, random search, successive halving, cross-validation. Keep it honest: focus, held-out set, nested cross-validation, record.

The guide describes a search as made of five parts: an estimator, a parameter space, a method for searching or sampling candidates, a cross-validation scheme and a score function.

How do grid search, random search and successive halving differ?

The three families trade completeness for speed, and the guide documents each of them.

MethodHow it worksStrengthWatch out for
Grid searchExhaustively considers all parameter combinationsComplete over the grid you defineCost grows with every added parameter and value
Random searchSamples a given number of candidates from a distributionA budget independent of the number of parameters; irrelevant parameters do not reduce efficiencyUse continuous distributions for continuous parameters
Successive halvingA tournament: all candidates start with few resources and only top performers advanceSpends more effort on promising candidatesMarked experimental in scikit-learn; needs a sensible minimum resource

Why is random search often preferred?

In Random Search for Hyper-Parameter Optimization, James Bergstra and Yoshua Bengio report that randomly chosen trials are more efficient than trials on a grid. Their Gaussian process analysis found that only a few hyperparameters matter for most datasets, and that the important ones differ from dataset to dataset.

That is why they call grid search a poor choice for new datasets and position random search as a natural baseline for more adaptive methods. For one widely used optimiser, see our entry on Adam optimization.

How do you avoid overfitting while tuning?

The scikit-learn guide warns that the final model should be evaluated on held-out samples not seen during the search. It recommends splitting the data into a development set for the search and an evaluation set for final metrics, and points to nested cross-validation as the best practice for evaluating a tuned model.

It also advises focusing on the few parameters that have a large impact and leaving the others at their defaults, and choosing a scoring metric that suits the task, for example when classes are unbalanced.

How does hyperparameter tuning relate to AI agents?

Agents depend on models whose settings were chosen at some point, and those choices should be repeatable. Teams building agents on ElixirClaw, the AI agents computing platform from XenonStack can treat each tuning run as a recorded experiment: the search space, the scoring metric, the data and the winning settings. Automating the whole loop is the subject of our entry on automated machine learning.

What should you do first when tuning hyperparameters?

  1. Read the model documentation and pick the few parameters that matter most.
  2. Start with random search and a fixed budget.
  3. Score every candidate with cross-validation and a metric that fits the task.
  4. Keep a separate evaluation set for the final check.
  5. Log the search space, metric, data version and result for each run.

To map one decision your agents make, and the data and policy it depends on, book a Context Workshop. See what happens in the workshop.

Frequently asked questions

What is a hyperparameter?

A hyperparameter is a parameter that is not directly learnt within an estimator. Examples include C, kernel and gamma for a support vector classifier and alpha for Lasso.

What is the difference between grid search and random search?

Grid search exhaustively considers all parameter combinations. Random search samples a given number of candidates from a distribution, so its budget does not depend on the number of parameters.

Is random search better than grid search?

Bergstra and Bengio report that randomly chosen trials are more efficient than trials on a grid, because only a few hyperparameters matter for most datasets and which ones matter varies.

How do you avoid overfitting during tuning?

Evaluate the final model on held-out samples that the search never saw. The scikit-learn guide recommends a development set and an evaluation set, and nested cross-validation for the most reliable estimate.

Interested in solving your challenges with the XenonStack team?
Get Started

Tell us about you and your priorities so we can prepare the right conversation. It takes about 2 minutes.

Please Select your Industry
Banking
Fintech
Payment Providers
Wealth Management
Discrete Manufacturing
Semiconductor
Machinery Manufacturing / Automation
Appliances / Electrical / Electronics
Elevator Manufacturing
Defense & Space Manufacturing
Computers & Electronics / Industrial Machinery
Motor Vehicle Manufacturing
Food and Beverages
Distillery & Wines
Beverages
Shipping
Logistics
Mobility (EV / Public Transport)
Energy & Utilities
Hospitality
Digital Gaming Platforms
SportsTech with AI
Public Safety - Explosives
Public Safety - Firefighting
Public Safety - Surveillance
Public Safety - Others
Media Platforms
City Operations
Airlines & Aviation
Defense Warfare & Drones
Robotics Engineering
Drones Manufacturing
AI Labs for Colleges
AI MSP / Quantum / AGI Institutes
Retail Apparel and Fashion

Continue