Skip to content

Hyperparameter

Also called: hyperparameters, hyper-parameter, hyper-parameters, hyperparameter tuning

Published:

How is a hyperparameter different from a parameter?

Google draws the line plainly: hyperparameters are values you control, parameters are values the model calculates during training [1]. The weights and bias of a linear model are parameters. scikit-learn describes hyperparameters as values not learnt directly within an estimator; they are passed as arguments when the estimator is constructed [2].

Which settings count as hyperparameters?

Google's three common examples are the learning rate, the batch size and the number of epochs [1]. Batch size is how many examples the model processes before updating its weights, and an epoch is one full pass through the training set [1]. In scikit-learn, typical examples are C, kernel and gamma for a support vector classifier, and alpha for Lasso [2].

The learning rate shows why the choice matters. Set it too low and the model takes a long time to converge; set it too high and it never converges, bouncing around the weights and bias that would minimise the loss [1].

How do you find good values?

scikit-learn recommends searching the hyperparameter space for the best cross-validation score [2]. GridSearchCV tries every combination in a grid, while RandomizedSearchCV samples a fixed number of candidates from given distributions, so the compute budget does not grow with the number of parameters [2]. Keep the test set out of this search, or its score will flatter the model [3].

Frequently asked questions

Is the learning rate a hyperparameter?

Yes. It is chosen before training and controls how far the model's parameters move at each step.

Which data should I tune hyperparameters on?

A validation set or cross-validation. The test set stays aside for the final evaluation.

Sources

  1. Linear regression: Hyperparameters — Google for Developers
  2. Tuning the hyper-parameters of an estimator — scikit-learn
  3. Cross-validation: evaluating estimator performance — scikit-learn