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.
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.
| Method | How it works | Strength | Watch out for |
| Grid search | Exhaustively considers all parameter combinations | Complete over the grid you define | Cost grows with every added parameter and value |
| Random search | Samples a given number of candidates from a distribution | A budget independent of the number of parameters; irrelevant parameters do not reduce efficiency | Use continuous distributions for continuous parameters |
| Successive halving | A tournament: all candidates start with few resources and only top performers advance | Spends more effort on promising candidates | Marked 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?
- Read the model documentation and pick the few parameters that matter most.
- Start with random search and a fixed budget.
- Score every candidate with cross-validation and a metric that fits the task.
- Keep a separate evaluation set for the final check.
- 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.