When talking about machine learning, Hyperparameters are the settings we define to control the process of training a model. Whilst the model’s parameters are learnt automatically during the training process (such as the coefficients in a linear regression), hyperparameters are settings that must be specified before training the model begins.
These hyperparameters directly affect the model’s ability to learn from the data and generalise to new datasets. Some common examples of hyperparameters include the learning rate in optimisation algorithms and the maximum depth of a decision tree, amongst others.
If the hyperparameters are chosen correctly, the model will perform better, whilst an incorrect choice will result in a model that does not fit the data well or that performs poorly on unseen data. In practice, finding the best values for the hyperparameters requires experience and trial and error to refine them over time.
The difference between a parameter and a hyperparameter
It is very common to confuse parameters with hyperparameters, but in reality they are two components of machine learning with very different functions. In machine learning, parameters are internal variables of the model which are automatically adjusted during training so that the model can perform the task for which it was designed.
For its part, Hyperparameters are values external to the model which are set before training and affect the way the model learns from the data, controlling aspects of the training process such as the learning rate, the complexity of the model or the number of iterations.
To put it simply, the algorithm uses the rules dictated by the hyperparameters to learn in a specific way based on the parameters.
Examples of hyperparameters
Some examples of commonly used hyperparameters are:
- Learning rate: This determines the speed at which the model learns from the data. A high rate would allow the model to learn from the data quickly, but it might be unstable and have a higher margin of error; a low rate is more stable, but the learning process might slow down too much.
- Number of iterations: This defines how many times the model sees all the data during training. More iterations result in better-quality learning, but too many would lead to overfitting, meaning that the model learns too much from a specific dataset and is unable to generalise its learning to other, different data.
- Batch size: How many data samples are used at once to train the model. If the datasets used by the model are large, it will learn more quickly and from a source containing more varied and richer information. On the other hand, a small dataset enables the model to gain more precise insights.
- Number of layers and neurons: These hyperparameters define the architecture of a neural network. The number of layers and neurons determines the model’s complexity and representational capacity. The greater the number of layers and neurons, the more complex the patterns the model will be able to learn; however, this can also increase the risk of overfitting if the model is too complex for the available data.
- Number of branches: In a decision tree, each node represents a question about a feature of the data and each branch represents a possible answer to that question. This hyperparameter controls the maximum depth of the tree and, therefore, how many splits are allowed before the tree reaches the leaves, which are the final predictions. A decision tree with many branches learns more complex patterns in the data, but also runs the risk of overfitting. On the other hand, a tree with few branches is simpler and more adaptable to other data, but may be less accurate and overlook essential patterns.


