What are hyperparameters in machine learning?
Hyperparameters are the settings chosen before training that control how a model learns, such as the learning rate, batch size, number of layers, and regularization strength. They differ from parameters, the weights and biases that training learns from data. Training cannot adjust a hyperparameter directly; the only way to judge one is to train with it and measure the result.
The right hyperparameters can decide whether a network trains at all. A learning rate ten times too high makes the loss diverge, and too little regularization lets a large model memorize its training set. Practitioners tune them by training several models and comparing their scores on a validation set, using grid search, random search, or Bayesian optimization.
Key ideas
- Parameters are learned by training; hyperparameters are chosen before it.
- The learning rate is usually the most important hyperparameter to tune.
- Batch size trades gradient noise against the cost of each update.
- Depth and width set how many parameters a network has.
- Regularization strength balances overfitting against underfitting.
- Random search usually beats grid search when only a few hyperparameters matter.
Common questions
Which hyperparameters should be tuned first?
Start with the learning rate, since it has the largest effect and interacts with almost everything else. Then tune regularization, such as weight decay and dropout, and the batch size. Architecture choices are usually taken from a known model and adjusted last.
Why must hyperparameters be tuned on a validation set?
Each comparison between settings uses the data it is scored on to make a choice. If that data is the test set, the final test score becomes optimistically biased. A separate validation set, or cross-validation, keeps the test set as an unbiased estimate of performance on new data.
What is Bayesian optimization for hyperparameters?
It fits a probabilistic model, often a Gaussian process, to the scores of past trials and uses it to choose the next setting worth trying. It balances trying settings near the best result so far with exploring regions the model is unsure about. It typically needs fewer trials than random search when each training run is expensive.
Are hyperparameters the same for every dataset?
No. Good defaults transfer reasonably well within a model family, such as a learning rate near 0.001 for Adam, but the best values depend on the dataset size, the model, and the batch size. A larger dataset usually needs less regularization, for example.
Related explainers
- Gradient Descent — Optimizing by following the slope downhill
- Learning Rate Scheduling — Step decay, cosine annealing, warmup, and the LR range test
- Regularization — Dropout, L1, and L2 — keeping models honest
- Epochs & Batching — How data is fed to the model in epochs, batches, and shuffles
- Cross-Validation — K-fold, stratified, and leave-one-out evaluation
- Train, Validation & Test Sets — Splitting data to measure generalization and avoid overfitting
References
- Bergstra & Bengio (2012), "Random Search for Hyper-Parameter Optimization", JMLR
- Snoek, Larochelle & Adams (2012), "Practical Bayesian Optimization of Machine Learning Algorithms"
- Li et al. (2016), "Hyperband: A Novel Bandit-Based Approach to Hyperparameter Optimization"
- Goyal et al. (2017), "Accurate, Large Minibatch SGD: Training ImageNet in 1 Hour"
- Loshchilov & Hutter (2017), "Decoupled Weight Decay Regularization"
Last updated