Parameters and Hyperparameters: Who Sets What
Learn which numbers training fits and which you choose, how to search for good settings and why the choice must be made on held-out data.
Key takeaways
- Parameters are learned by the training procedure, while hyperparameters configure that procedure or the model family.
- Training error usually favors the most flexible setting, so choose hyperparameters with a validation set or cross-validation.
- A few settings, often the learning rate and the controls on model size or regularization, tend to matter most.
- Search on a log scale when plausible values span several powers of ten.
- Every choice you tune, including preprocessing and thresholds, uses up some of the validation set's honesty.
Parameters are the numbers a training algorithm fits from data, such as the weights of a linear model. Hyperparameters are the settings fixed from outside that fit, such as how strongly to penalize large weights or how deep a tree may grow. You, or a search procedure you set up, choose the hyperparameters. The training algorithm then chooses the parameters.
The practical difference is where the choice is judged. Parameters are fitted on training data. Hyperparameters are compared on validation data, because training data would often give a misleading answer.
Examples across model types
| Model | Parameters (learned) | Hyperparameters (chosen) |
|---|---|---|
| Linear or logistic regression | Weights and intercept | Penalty type and strength |
| Decision tree | Split features, thresholds, leaf values | Maximum depth, minimum leaf size |
| k-nearest neighbors | None in the usual sense; stores the data | k, distance measure |
| k-means | Cluster centers | Number of clusters, initialization |
| Boosted trees | Splits and leaf values of every tree | Number of trees, learning rate, depth |
| Neural network | Weights and biases | Layers, widths, learning rate, batch size, epochs |
The k-nearest neighbors row shows that the amount of stored information need not be a fixed list of parameters. That distinction is the subject of parametric and nonparametric models.
A worked example: ridge regression
Take one feature, no intercept, and the data x = (1, 2, 3), y = (2, 4, 6). Ridge regression minimizes the sum of squared errors plus λw², where λ is a penalty strength. Setting the derivative to zero gives a closed form.
w = Σxy / (Σx² + λ)
Σxy = 2 + 8 + 18 = 28
Σx² = 1 + 4 + 9 = 14
λ = 0 → w = 28 / 14 = 2.00
λ = 2 → w = 28 / 16 = 1.75
λ = 14 → w = 28 / 28 = 1.00 Here w is a parameter and λ is a hyperparameter. For each λ, the data determine w. The data used for fitting cannot sensibly determine λ: λ = 0 always gives the smallest training squared error, since the penalty only pulls w away from the best training fit.
In this noise-free toy, λ = 0 is also right. With noisy data and many features, a positive λ often predicts new points better. Ridge regression explains why.
What changes when you turn the dial
It helps to know which way each setting pushes. Many hyperparameters control capacity, the range of patterns a model can fit. Raising tree depth, adding hidden units or lowering a penalty lets the model follow the training data more closely. Past some point, it starts following noise, and validation error rises while training error keeps falling.
Watch the direction of each scale, because libraries differ. In some, a larger regularization number means a stronger penalty. In scikit-learn's logistic regression and support vector machines, the parameter named C works the other way: a larger C means a weaker penalty. Reading it backward is an easy and common error.
Other settings mainly control the optimization: learning rate, batch size, momentum, number of iterations. They affect whether and how fast training reaches a good solution, and they can also influence which solution is found. A third group controls randomness and resources, such as how many features each tree split may consider or how much data each round sees.
When validation results disappoint, this grouping tells you where to look. If training error is high, check optimization settings and capacity. If only validation error is high, turn toward regularization and data.
Two nested loops
Tuning works as an outer loop around training.
- Choose a candidate set of hyperparameters.
- Fit the parameters on the training data with those settings.
- Score the fitted model on validation data.
- Repeat for other candidates.
- Keep the best setting, optionally refit on training and validation data together, and score once on the test set.
If data is limited, replace the single validation split with cross-validation: repeat steps 2 and 3 over several folds and average.
Why the validation score becomes optimistic
When you try many settings and keep the winner, part of its lead is luck on that particular validation set. The more candidates and the smaller the set, the larger this effect. The winner's validation score is therefore a biased estimate of future performance.
This is why a separate test set exists, as laid out in the three data splits. When you must both tune and estimate performance from one small dataset, nested cross-validation puts the search inside an outer loop of held-out folds.
Where the line blurs
Not every setting sorts neatly.
- Number of training epochs is a hyperparameter, but early stopping chooses it during training by watching validation loss.
- Learning rate can follow a schedule, where you choose the schedule and its settings.
- Decision threshold is picked after fitting. It is a choice made on validation data, so treat it like a hyperparameter.
- Preprocessing choices, such as how to impute or which features to keep, belong in the search too.
- Random seed should not be tuned. Picking the luckiest seed rarely carries over, so report variation across seeds instead.
In Bayesian methods, a prior has its own settings, also called hyperparameters, which may themselves be estimated from data. The vocabulary depends on which level of the model you are standing on.
Which settings to tune first
Defaults in good libraries are reasonable starting points, though not optimal for your data, and they can change between versions. Record the values you used.
For gradient-trained models, the learning rate is usually the first thing to get right: too high and loss jumps or diverges, too low and progress crawls. For tree ensembles, the number of trees together with the learning rate, and tree depth or leaf size, tend to matter. For penalized linear models, the penalty strength is the main control.
Change a few influential settings over wide ranges before fine-tuning many minor ones. Priorities under a compute budget discusses this for neural networks.
How to search
| Method | How it picks candidates | Good when |
|---|---|---|
| Manual | Your judgment | Exploring and learning behavior |
| Grid | Every combination of listed values | One or two settings |
| Random | Draws from ranges you define | Several settings, uneven importance |
| Model-based | Uses past results to propose the next | Each run is expensive |
| Successive halving | Many short runs, extends the promising | Partial training is informative |
With nine trials over two settings, a 3 × 3 grid tests only three distinct values of each. Nine random draws usually test nine distinct values of each, which helps when one setting matters far more than the other.
For quantities such as a learning rate or penalty, sample on a log scale, so that the range 0.0001 to 0.001 gets as much attention as 0.01 to 0.1. If the best value sits at the edge of your range, widen it.
Practical habits
Set a budget before you start, in number of runs or hours. Log every trial, including failures, with its settings, data version and score. Compare the spread across folds or seeds with the differences between settings; if they are similar, prefer the simpler or cheaper option.
Always include the default configuration as one candidate. It shows how much tuning bought you. Often better features or cleaner labels would give a larger improvement than another hundred trials, and error analysis can tell you whether that is so.
When you hand a model to someone else, report both sets of numbers appropriately: the hyperparameters as configuration that can reproduce the run, and the parameters as the saved artifact. Retraining on new data will give new parameters. Whether the old hyperparameters are still good is something to recheck from time to time, particularly after the data volume grows a lot.
Settings interact
Hyperparameters rarely act alone. In boosting, a smaller learning rate usually needs more trees to reach the same training fit, so tuning one while the other stays fixed can mislead you. In neural networks, a different batch size often calls for a different learning rate. Penalty strength depends on the scale of the features and on the number of examples, especially when the loss is a sum in one library and an average in another.
For the same reason, copying settings between tools is risky even when the names match. Check the documented formula for the objective.
Searching one setting at a time, holding others at defaults, is cheap and can settle into a poor combination. Searching interacting settings jointly, with random or model-based methods, avoids that. After a search, plot validation score against each setting. A clear trend tells you where to extend the range. A flat cloud suggests the setting hardly matters in the region you tried, so you can fix it and spend the budget elsewhere.
Keeping a record someone can use
Write down every hyperparameter of the chosen model, including those you left at their defaults, since a library upgrade can change a default and silently change your results. Note the search ranges, the number of trials, the validation scheme and the data version. A reader can then judge how much selection took place and repeat the work.
Store the preprocessing configuration with the model settings. A threshold, an imputation rule or a list of selected columns is part of the system, and losing any one of them makes the saved weights hard to use correctly.
A short vocabulary check
In conversation, people sometimes say "tuning parameters" when they mean hyperparameters, and "model parameters" when they mean any configurable option. Statistics texts may call a penalty strength a tuning parameter. Ask two questions of any number you meet: what process set it, and which data did that process look at? The answers tell you how to treat it, whatever it is called.