翻篇收录说明
翻篇网页快照

What is hyperparameter optimization? Tuning methods and examples

https://telnyx.com/learn-ai/hyperparameter-optimization

最近抓取:2026-12-05 02:44:54(北京时间)

最近内容变化:2026-12-02 14:12:25(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

Hyperparameter optimization, or tuning, finds the settings that control how a model learns. What hyperparameters are, how tuning works, and the methods.

正文摘录

Back to GlossaryWhat is hyperparameter optimization? Tuning methods and examplesHyperparameter optimization, or tuning, finds the settings that control how a model learns. What hyperparameters are, how tuning works, and the methods.Editor: Andy MunsUpdated October 2026Hyperparameter optimization (HPO), also called hyperparameter tuning, is the search for the hyperparameter values that give a machine learning model its best performance on data it was not trained on. Hyperparameters are the settings fixed before training starts, such as the learning rate or the depth of a decision tree. The model learns its parameters from data; its hyperparameters decide how that learning runs.Tuning can matter as much as the model itself. When Melis, Dyer and Blunsom carefully re-tuned an older kind of language model, it outperformed newer designs.What is hyperparameter optimization?Hyperparameter optimization chooses the settings that training runs under. Training, sometimes called parameter optimization, fits a model's parameters to data.One example is a model that tells a voice AI agent why someone is calling, built with gradient-boosted trees. Before training, someone has to pick its learning rate and how deep each tree can grow.Each choice gives a different model. HPO tries candidate settings, trains a model with each, scores it on calls held out from training and keeps the best.What is a hyperparameter?A hyperparameter is a setting that is fixed before training and is not learned from the data. Each kind of model has its own:A neural network has a learning rate, how big a step training takes each time it adjusts the weights, and a batch size, how many examples it looks at before each step.It also has a number of epochs, or full passes through the training data, and a number of layers.Gradient-boosted trees, as in XGBoost, have a learning rate too, plus the depth of each tree and the number of trees.A support vector machine has C, which trades training errors against a wider margin, and gamma, which sets how far one training example's influence reaches.For a neural network, the learning rate is usually the first to tune. Bengio calls it often the single most important hyperparameter.Hyperparameters vs parametersParameters are what the model learns. In a neural network they are the weights; in gradient-boosted trees they are the split points and the values in each leaf. The finished model is made of them.Hyperparameters are set outside training, by a person or a tuning method. A learning rate shapes the weights a network ends up with, but the finished model does not contain it.A quick test: if training changes it, it is a parameter. If it has to be set before training starts, it is a hyperparameter.Why hyperparameter optimization mattersThe same model can look weak or strong depending on its settings. They decide whether it underfits or overfits, the balance known as the bias-variance tradeoff.For the call-intent model, trees that are too shallow miss patterns in the calls. Trees that are too deep memorize the training calls and fail on new ones.Tuning also decides which of two models looks better. In a large study of image-generating models known as GANs, Lucic and colleagues found that most could reach similar scores with enough tuning and repeated runs.How hyperparameter optimization worksA tuning run is a loop. Bischl and colleagues describe it as proposing a configuration, evaluating it and updating the tuning method with the result.Before the loop starts, the data is split three ways: training calls to fit each candidate, validation calls to score it, and a test set that stays locked until the end. For the call-intent model, one run looks like this:The search space lists each hyperparameter and the range it can take: a learning rate between 0.01 and 0.3, and a tree depth from 2 to 8. The learning rate is searched on a log scale, so 0.01 to 0.03 gets as many tries as 0.1 to 0.3.A validation metric is chosen, such as accuracy on the validation calls.The tuning method picks a setting, a model is trained with it on the training calls, and the model is scored on the validation calls.The method uses that score to pick the next setting, and the loop repeats until the budget of trials runs out.The best setting is retrained on the training and validation calls together and scored once on the test set.Instead of one fixed validation split, cross-validation rotates it. Everything except the test set is split into k folds; each candidate trains k times, holding out a different fold each time, and its score is the average.The test set stays out of the loop because a search overfits whatever it scores against. Picking the best of many settings on one validation set makes that score look better than the model really is.Nested cross-validation does the same job without a fixed test set: it runs the whole tuning loop inside each fold of an outer cross-validation. Bischl and colleagues recommend it for reporting an unbiased score.Hyperparameter optimization methodsTuning methods differ mainly in how they choose the next setting to try. A run that tries many settings is often called a hyperparameter sweep.Manual search, a person adjusting settings by hand, is still common. Bergstra and Bengio named grid search and manual search as the most widely used strategies.Grid searchGrid search lists a few values for each hyperparameter and trains a model on every combination. Three learning rates and three tree depths make nine runs.The number of runs grows exponentially with each hyperparameter added, which Feurer and Hutter call the curse of dimensionality. Five values each for four hyperparameters already means 625 runs.Random searchRandom search samples each setting from a range instead of a fixed list. In Bergstra and Bengio's tests on neural networks, it found models as good as or better than grid search did, in a small fraction of the computation time.The reason is that only a few hyperparameters usually matter, and which ones matter differs from one dataset to the next.With nine trials and one important hyperparameter, a 3 by 3 grid tests the important one at only three values. Nine random trials test it at nine different values.Bayesian optimizationBayesian optimization learns from the trials it has already run. It fits a model of how settings relate to scores and uses it to choose the most promising next setting.Snoek, Larochelle and Adams model performance with a Gaussian process, which predicts a score for settings not yet tried and how uncertain that prediction is.The next trial goes where the predicted score is good or the uncertainty is high, balancing settings known to work against ones not yet explored. With careful choices, Snoek and colleagues showed, this can exceed expert-level tuning.The tree-structured Parzen estimator (TPE) instead splits past trials into good and bad scores and picks settings that look like the good group. It is the default method in Optuna.SMAC, another common method, uses random forests in place of a Gaussian process.Feurer and Hutter note that guided methods like these usually outperform random search.Early stopping and HyperbandEarly stopping here means dropping a candidate setting partway through, not the rule that ends one training run when validation loss stops improving. Many settings look bad early, so there is no need to train them to the end.Methods that judge settings on cheap, partial training like this are called multi-fidelity methods.Successive halving gives every candidate the same small budget, drops the worse half and repeats with the rest. With 64 settings, each gets one training round; the best 32 get two rounds, the best 16 get four, and so on until one remains.Successive halving has to guess how much training a setting needs before its quality shows. Too little, and slow starters are dropped; too much, and few settings get tried.Hyperband runs successive halving at several starting budgets to cover both cases. Li and colleagues report over an order-of-magnitude speedup over popular Bayesian optimization methods on deep learning and kernel-based problems.Population-based trainingPopulation-based training tunes while it trains. A population of models trains in parallel.From time to time, a weak model copies the weights and hyperparameters of a stronger one. It then changes the hyperparameters slightly and keeps training.The result is a schedule of hyperparameter settings rather than one fixed set for the whole run.Hyperparameter tuning toolsLibraries run the tuning loop, so the code mostly defines the search space and the score. In scikit-learn, the run from the steps above fits in a short script. Its built-in breast cancer dataset (569 examples) stands in for call data here:Pythonfrom scipy.stats import loguniform, randintfrom sklearn.datasets import load_breast_cancerfrom sklearn.ensemble import HistGradientBoostingClassifierfrom sklearn.model_selection import RandomizedSearchCV, train_test_splitX, y = load_breast_cancer(return_X_y=True)X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)search = RandomizedSearchCV( HistGradientBoostingClassifier(random_state=0), param_distributions={ "learning_rate": loguniform(0.01, 0.3), "max_depth": randint(2, 9), }, n_iter=20, cv=5, random_state=0,)search.fit(X_train, y_train)best = search.best_params_print(round(best["learning_rate"], 3), best["max_depth"])print(round(search.best_score_, 3), round(search.score(X_test, y_test), 3))RandomizedSearchCV tried 20 settings, scoring each with 5-fold cross-validation on the 455 examples outside the test set. It picked a learning rate of 0.142 and a tree depth of 8, with a cross-validation accuracy of 0.974.On the 114 test examples it never saw, the tuned model scored 0.956, and that is the number to report. The 0.974 was the best of 20 scores, so it can run high, though one run cannot show by how much.scikit-learn also has GridSearchCV, which tries every combinati