AI glossary

Hyperparameters

Hyperparameters are configuration settings that define the structure and control the behavior of a learning algorithm before the training process begins. Unlike model parameters, which are learned automatically from data during training, hyperparameters are set by the practitioner and remain fixed while the algorithm adjusts its internal weights. They act as the primary levers for managing the trade-off between underfitting and overfitting, directly influencing how a model learns patterns from its input data.

How it works

The distinction between hyperparameters and model parameters is fundamental to understanding how machine learning systems operate. Model parameters, such as the weights and biases in a neural network or the splitting rules in a decision tree, are the internal variables that the algorithm optimizes to minimize error. These values are updated iteratively as the model processes training data. In contrast, hyperparameters are external configurations that govern the learning process itself. They determine the architecture of the model, the speed at which it learns, and the constraints placed on its complexity. Because they are not derived from the data, they must be specified by the human operator or an automated tuning system before the learning algorithm commences.

Hyperparameters influence the learning dynamics in several distinct ways. In neural networks, the number of hidden layers and the number of neurons within those layers define the model’s capacity to represent complex functions. A deeper network with more layers can capture intricate patterns but requires more data and computational resources to train effectively. The learning rate, another critical hyperparameter, controls the size of the steps the algorithm takes when updating model parameters. If the learning rate is too high, the model may overshoot the optimal solution and fail to converge; if it is too low, the training process may become excessively slow or get stuck in local minima. Other examples include the maximum depth of a decision tree, which limits how many questions the tree can ask before making a prediction, and the regularization strength, which penalizes model complexity to prevent overfitting.

Selecting the correct values for these hyperparameters is often referred to as hyperparameter tuning or optimization. This process involves testing different combinations of settings to find the configuration that yields the best performance on a validation set. The goal is to identify a balance where the model is complex enough to capture the underlying patterns in the data but simple enough to generalize well to new, unseen data. Common strategies for this search include grid search, where a predefined set of values is exhaustively tested, and random search, where values are sampled from a distribution. More advanced methods may use Bayesian optimization or genetic algorithms to intelligently navigate the hyperparameter space, evaluating how different settings affect the model’s ability to learn effectively.

Where it is used

Hyperparameters are used across virtually all machine learning and artificial intelligence techniques, though their specific forms vary depending on the algorithm. In supervised learning tasks such as classification and regression, hyperparameters control the trade-off between bias and variance. For instance, in linear regression, a regularization hyperparameter might be used to shrink coefficients and reduce overfitting. In decision tree algorithms, hyperparameters like maximum depth or minimum samples per leaf control the granularity of the splits, preventing the tree from memorizing noise in the training data. In support vector machines, the choice of kernel and the regularization parameter are critical hyperparameters that determine the shape of the decision boundary.

In deep learning, hyperparameters play an even more prominent role due to the complexity and scale of the models. Neural networks require careful tuning of the learning rate, batch size, and network architecture. The batch size, which determines how many samples are processed before the model’s parameters are updated, affects both the stability of the gradient estimates and the speed of training. The choice of activation functions, while often considered part of the architecture, can also be treated as a hyperparameter that influences the model’s ability to learn non-linear relationships. Additionally, in reinforcement learning, hyperparameters such as the discount factor determine how much future rewards are valued compared to immediate rewards, shaping the agent’s long-term strategy.

Hyperparameters are also central to unsupervised learning and semi-supervised learning approaches. In clustering algorithms, the number of clusters to identify is a key hyperparameter that must be specified or estimated. In dimensionality reduction techniques like principal component analysis, the number of components to retain is a hyperparameter that controls the amount of information preserved from the original dataset. In semi-supervised learning, where labeled and unlabeled data are used together, hyperparameters may control the balance between the loss calculated on labeled data and the loss calculated on unlabeled data, influencing how much the model relies on each type of information.

Limitations and trade-offs

The primary limitation of hyperparameter tuning is the computational cost associated with searching for the optimal configuration. Because hyperparameters are not learned from data, evaluating a single configuration requires running the full training process, which can be time-consuming and resource-intensive, especially for large models or large datasets. Exhaustive search methods like grid search can become prohibitively expensive as the number of hyperparameters increases, a phenomenon known as the curse of dimensionality. Even random search, which is generally more efficient, requires multiple training runs to achieve reliable results. This cost is compounded when hyperparameter tuning is performed alongside model selection, where different algorithm types are also being compared.

Another trade-off involves the balance between model complexity and generalization. Hyperparameters that increase model capacity, such as adding more layers or neurons, can improve performance on training data but may lead to overfitting if not properly constrained. Conversely, hyperparameters that restrict complexity, such as high regularization strength or shallow tree depth, can prevent overfitting but may result in underfitting, where the model is too simplistic to capture the underlying patterns in the data. Finding the “sweet spot” requires careful validation and often domain knowledge or empirical testing. Furthermore, hyperparameters are often interdependent; changing one value, such as the learning rate, may necessitate adjustments to others, such as the batch size or the number of training epochs, making the optimization landscape complex and non-linear.

  • Model Parameter - Hyperparameters are the external settings that control how model parameters are learned.
  • Hyperparameter (Hyperparameter Tuning) - The process of optimizing hyperparameters to improve model performance.
  • Bias-Variance Tradeoff - Hyperparameters are the primary tools used to balance bias and variance.
  • Underfitting - A state often caused by hyperparameters that restrict model complexity too much.
  • Regularization - A technique controlled by hyperparameters to prevent overfitting.
  • Cross-Validation - A method used to evaluate hyperparameter configurations effectively.