Hyperparameter
Study guides: Exam SRM, Exam PA
A hyperparameter is a setting fixed before a model is fitted that controls how the fitting works — usually how flexible the model may become — such as the penalty \lambda in regularized regression, the pruning penalty \alpha of a Decision Tree or the number of predictors m tried at each split of a Random Forest. Unlike a parameter (\beta_j, a split point), it is not estimated by minimizing training error, because training error always favours the most flexible setting; it is chosen by estimating test error, usually by Cross-Validation.
\hat{\lambda} = \arg\min_{\lambda}\ \text{CV}_{(k)}(\lambda)
\text{CV}_{(k)}(\lambda) = \frac{1}{k}\sum_{j=1}^{k}\text{MSE}_j(\lambda)
\hat{\lambda}_{\text{1SE}} = \max\left\{\lambda : \text{CV}(\lambda) \le \text{CV}(\hat{\lambda}) + \text{SE}(\hat{\lambda})\right\}
\text{MSE}_j(\lambda)is the error on foldjof a model fitted to the otherk-1folds at that\lambda(deviance or error rate for a GLM or classifier). The one-standard-error rule takes the simplest model whose CV error is within one standard error of the minimum — for a penalty, the largest such\lambda. After tuning, the model is refit on all the training data at the chosen value.- SRM's tree ensembles (Tree Ensemble): Bagging — the number of trees
B, which is not critical, since a largeBdoes not overfit; random forests —Bandm, typicallym \approx \sqrt{p}(m = pis bagging); Boosting —B(too many trees can overfit, so it is cross-validated), the shrinkage\lambda(small, such as0.01or0.001, needing a largerB) and the interaction depthd(d = 1, stumps, often works well). - Regularized regression (PA): ridge and lasso tune
\lambda, after standardizing the predictors; the elastic net also tunes the mixing weight —alphain R'sglmnet, wherealpha = 1is the lasso andalpha = 0ridge. - Each hyperparameter moves the model along the Bias-Variance Tradeoff: a larger
\lambdaor\alpha, a smallerdor a largerKin K-Nearest Neighbors means less flexibility, more bias and less variance.
Choosing the Lasso Penalty for a Frequency GLM A Poisson lasso for auto claim frequency is fitted over a grid of
\lambda. Ten-fold CV gives:
\lambdaCV deviance SE Nonzero coefficients 0.001104.82.3180.01102.12.2140.05101.02.090.10102.62.160.20104.32.440.50109.52.82Find the
\lambdachosen by minimum CV error and by the one-standard-error rule.Answer The minimum is
101.0at\lambda = 0.05. For the one-standard-error rule:\begin{align*} \text{threshold} &= 101.0 + 2.0 \\ &= 103.0 \end{align*}The values of
\lambdawith CV deviance at most103.0are0.01,0.05and0.10; the rule takes the largest,\lambda = 0.10(102.6 \le 103.0, while\lambda = 0.20gives104.3).Minimum CV picks
\lambda = 0.05with9rating variables; the one-standard-error rule picks\lambda = 0.10with6— a model statistically indistinguishable in predictive accuracy and easier to file and explain.
Hyperparameters of a Severity Forest and a Boosted Model A modeller has
p = 12predictors. (a) Whatmwould a random forest typically use for a classification of large losses, and what is the model withm = 12? (b) For boosted trees, which ofB,\lambdaanddcan cause overfitting if set too large, and what happens to the requiredBif\lambdais cut from0.1to0.01?Answer (a)
m \approx \sqrt{12} = 3.46, so3or4predictors per split. Withm = 12 = pevery predictor is available at every split: that is bagging, and its trees are more correlated, so averaging them reduces variance less.(b)
B: boosting fits each tree to the current residuals, so too many trees overfit — unlike bagging and random forests.d: deeper trees fit higher-order interactions and more variance. A larger\lambdalearns faster and can overfit with fewer trees. Cutting\lambdatenfold slows learning, so a much largerBis needed to reach the same fit;Band\lambdaare tuned together.
How it appears on the exam
- SRM (multiple choice): describe bagging, boosting and random forests and the hyperparameters used to control them — true/false statements on
B,m,\lambdaanddand what happens as each grows.- SRM: read a CV error curve or table and pick the tuning value, often paired with the pruning penalty
\alphaor a ridge/lasso\lambda.- PA (written): select appropriate hyperparameters for regularized regression — justify
\lambda(and the elastic-net mix) from CV output, minimum versus one-standard-error, and explain the effect on the coefficients.
Exam traps
- Hyperparameter vs parameter. Coefficients and split points are estimated from the training data;
\lambda,\alpha,m,B,dare not. Calling the lasso coefficients "hyperparameters" is wrong.- Tuning on the test set. Choosing
\lambdaby test-set error and then reporting that error as the model's performance is optimistic — the test set has been used to fit. Tune by CV on the training data; touch the test set once.- Direction of the penalty. A larger
\lambdameans a simpler model. The one-standard-error rule therefore moves to the right of the minimum in\lambda, not to the left.Bbehaves differently. LargeBis harmless for bagging and random forests but can overfit boosting.- Two alphas.
glmnet'salphais the ridge–lasso mixing weight; the\alphaof cost-complexity pruning is a penalty per terminal node.