Hyperparameter (Hyperparameter Tuning)

Home Glossary Item Hyperparameter (Hyperparameter Tuning)
« Back to Glossary Index

A hyperparameter is a configuration variable external to a machine learning model that cannot be learned directly from the training data. These variables control the training process and the structure of the model, remaining constant throughout the learning phase. Hyperparameter tuning is the systematic process of selecting the optimal set of these values to maximize the predictive accuracy of the model.

How it works

Machine learning models rely on two distinct types of variables: parameters and hyperparameters. Parameters, such as the weights and biases in a neural network, are internal values that the algorithm adjusts automatically during training by analyzing the data. In contrast, hyperparameters are set by the practitioner before training begins and govern how the learning process itself unfolds. Because they are not derived from the data, they must be chosen based on domain knowledge, experimentation, or optimization algorithms. Common examples include the learning rate, which dictates the step size during optimization; the number of hidden layers in a deep learning architecture; the value of ‘k’ in k-nearest neighbors; and the regularization parameters ‘C’ or ‘gamma’ in Support Vector Machines.

Hyperparameter tuning, also known as hyperparameter optimization, involves searching through a defined space of possible hyperparameter combinations to find the configuration that yields the best model performance. This search is critical because the performance of machine learning algorithms is highly dependent on the specific values chosen. The goal is to navigate this search space efficiently to achieve the highest possible predictive accuracy. The process typically involves defining a search strategy, evaluating candidate configurations, and iterating until an optimal or satisfactory set of hyperparameters is identified.

Several strategies exist to perform this search. Grid search is a foundational method that builds and evaluates a model for every possible combination of hyperparameters specified in a predefined grid. Random search improves efficiency by randomly selecting combinations of hyperparameters to evaluate, rather than exhaustively testing every possibility. More advanced methods, such as Bayesian Optimization and Gradient-based Optimization, build a probability model of the objective function to intelligently predict which hyperparameter values are likely to yield the best results, thereby navigating the search space more efficiently than exhaustive or random approaches.

Where it is used

Hyperparameter tuning is applied across a wide range of machine learning tasks where model performance is sensitive to configuration settings. It is essential in supervised learning scenarios, such as classification and regression, where the choice of algorithm structure and learning dynamics directly impacts accuracy. For instance, in k-nearest neighbors, the value of ‘k’ determines the balance between sensitivity to local noise and generalization to broader trends. In Support Vector Machines, the choice of kernel parameters like ‘C’ and ‘gamma’ controls the trade-off between achieving a low training error and a low testing error.

The technique is also central to deep learning, where models often have numerous hyperparameters that influence convergence and generalization. These include the number of hidden layers, the number of neurons per layer, the learning rate, and the batch size. In these complex architectures, small changes in hyperparameters can lead to significant differences in training speed and final model quality. Additionally, hyperparameter tuning is used in unsupervised learning tasks, such as clustering, where parameters define the number of clusters or the distance metrics used to group data points.

Limitations and trade-offs

The primary trade-off in hyperparameter tuning is the computational cost versus the potential gain in model performance. Exhaustive methods like grid search can be computationally expensive and time-consuming, especially when the number of hyperparameters is large or the search space is wide. Each combination requires training a model from scratch, which can be prohibitive for large datasets or complex architectures. Random search offers a balance by reducing the number of evaluations needed, but it still requires significant resources compared to methods that learn from previous evaluations.

Another limitation is the risk of overfitting to the validation data. If the hyperparameter search is too extensive, the selected configuration might be optimized for the specific validation set rather than generalizing well to unseen data. This is particularly relevant when using complex optimization strategies that make many queries to the validation set. Additionally, the choice of hyperparameters is often interdependent; changing one parameter may require adjusting others to maintain optimal performance, making the search space non-linear and difficult to navigate. Advanced methods like Bayesian Optimization help mitigate these issues by modeling the objective function, but they introduce their own complexity and computational overhead.

Related terms

  • Model Parameter – Hyperparameters are external configuration variables, whereas model parameters are internal values learned from data during training.
  • Learning Rate – A specific and critical hyperparameter that controls the step size during the optimization process.
  • Objective Function – The function that hyperparameter tuning seeks to optimize, typically by maximizing predictive accuracy or minimizing error.
  • Cross-Validation – A technique often used in conjunction with hyperparameter tuning to ensure that the selected hyperparameters generalize well to unseen data.
  • Regularization – A technique that often involves hyperparameters (like ‘C’ or ‘gamma’) to prevent overfitting by penalizing model complexity.
« Back to Glossary Index
Eugene Serbin

Systems Analyst and AI Engineer, Semalt

Eugene Serbin is a systems analyst and AI engineer at Semalt. He graduated with honours from Kharkiv National University of Radio Electronics in 2005, specialising in intelligent decision-making systems, and holds a second degree from the same university in economic cybernetics. He writes and edits the AI research summaries, applied machine learning explainers and the glossary on ai-magazine.com.