All terms

Glossary

Hyperparameter Tuning

Hyperparameter tuning is the search for the training settings, such as learning rate and batch size, that give a model its best validation score.

Lyzr Team8 min read

Two teams can train the same model on the same data and get very different results. The difference is often a handful of settings that nobody told the model to learn.

In one line

Hyperparameter tuning is the process of searching for the best values of settings chosen before training, such as learning rate, batch size or tree depth, by comparing models on validation data.

What is hyperparameter tuning?

A hyperparameter is a setting you choose before training starts. The model never learns it from data. Examples are the learning rate, the batch size, the number of layers, and the depth of a decision tree. Hyperparameter tuning is the search for the combination that gives the best score on data the model did not train on.

It is also called hyperparameter optimization. The workflow is simple: pick values, train, score on a validation set, then repeat with different values and keep the best.

What are hyperparameters in machine learning?

Hyperparameters are the knobs on the training process and on the model's structure, as opposed to parameters, which are the weights learned during training. A neural network learns millions of weights, but a person or a script sets a few dozen hyperparameters.

Common ones include the learning rate, the batch size, the number of epochs, regularization strength, and the number of trees in a random forest. Which ones matter most depends on the model, and the learning rate is usually the first to check in deep learning.

Why is hyperparameter tuning important?

Poor settings can make a good model look bad. A learning rate that is too high makes training unstable, and one that is too low wastes time or stalls. Too much model capacity, or too little regularization, leads to overfitting.

Tuning also keeps comparisons fair. If one model gets a careful search and the other gets defaults, the result says more about effort than about the models.

What are the main hyperparameter tuning strategies?

There are four common strategies, and they trade effort against the quality of the search.

  • Manual search: an experienced person adjusts values by judgement. It is cheap but hard to reproduce.
  • Grid search: tries every combination from a fixed list of values.
  • Random search: samples combinations at random from ranges.
  • Bayesian optimization: builds a model of past results to choose the next trial.

Automated tools wrap these strategies, and automated machine learning systems usually include tuning as a built in step.

Hub with tuning in the centre and four strategies: manual, grid, random and Bayesian optimization.

How does grid search work?

Grid search tries every combination of values from lists you provide. With three learning rates and four batch sizes, it trains twelve models and keeps the best one. It is easy to understand and covers the grid thoroughly.

The cost grows quickly. Each extra hyperparameter multiplies the number of runs, so grids become impractical beyond a few settings. A grid can also miss a good value that sits between two listed points.

Random search samples values from ranges instead of a fixed list. Often only a few hyperparameters strongly affect the result. A grid repeats the same few values of those important settings across many trials, while random sampling tries a new value of each one in every trial. Bergstra and Bengio showed this in a widely cited 2012 paper.

Random search also lets you stop at any time and has a budget you control: ten trials cost ten runs, however many hyperparameters there are.

What makes Bayesian optimization different?

Bayesian optimization uses the results of earlier trials to decide where to look next. It fits a cheap statistical model of how settings relate to score, then picks values that look promising or are still uncertain. It tends to need fewer trials when each training run is expensive.

Teams often add pruning or early stopping, which ends trials that are clearly behind. Whichever strategy you pick, tune against a validation set and report the final score on a separate test set, so the search does not overfit the data it was scored on.

Four steps in a loop: pick settings, train a model, score on validation, keep the best.

Spot the failure

Quick test

A team runs 200 random search trials, picks the one with the highest score on the test set, and reports that score as the expected accuracy. In production, accuracy is lower. What went wrong?

Show the answer

The test set was used to choose the winner, so the reported score is optimistic. Tuning should compare trials on a validation set. The test set should be used once, after the choice is final.

  • Learning rate: usually the most influential hyperparameter in deep learning
  • Batch size: a core setting that tuning searches over
  • Epochs: how many passes training makes, often set automatically with early stopping
  • Overfitting: the failure good tuning and validation guard against
  • Fine-tuning: changes weights with new data, where tuning changes the run settings

Frequently asked questions

What is the difference between a parameter and a hyperparameter?

Parameters, such as weights, are learned from data during training. Hyperparameters are set before training and control how it runs or how the model is built.

What is the difference between hyperparameter tuning and fine tuning?

Fine tuning continues training a pretrained model on new data, which changes its weights. Hyperparameter tuning searches for the best training settings. A fine tuning run has hyperparameters that can be tuned.

Which hyperparameter should I tune first?

In deep learning, start with the learning rate. For tree models, start with tree depth and the number of trees, plus the learning rate for boosted trees. Tune the few settings that move the score most before the rest.

Is hyperparameter tuning only for deep learning?

No. Random forests, gradient boosted trees, support vector machines and linear models all have hyperparameters that affect results.

How many trials are enough?

There is no fixed number. Set a budget, watch whether the best score is still improving, and stop when new trials stop helping.

Got a use case in mind?

8 weeks from use case to agents running in production.

Platform, people and FDEs, all in. Bring your environment. We'll co-build and stay until it's live.

Talk to Us

Continue reading

You might also like

Build with Lyzr

Try it in Agent Studio

From framework-agnostic design to production-grade agents, deployed in under 24 hours.