Actuarial Notes

Hyperparameter

Study guides: Exam SRM, Exam PA, Exam ACIA-CAPSTONE

A Hyperparameter is a setting fixed before a model is fitted that controls how the fitting works, usually how flexible the model may become. Examples are the penalty \lambda in regularized regression, the pruning penalty \alpha of a decision tree and the number of predictors m tried at each split of a random forest.

Unlike a parameter (\beta_j, a split point), a hyperparameter 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. With k folds and a grid of values of \lambda, the value chosen is

\hat{\lambda} = \arg\min_{\lambda}\ \text{CV}_{(k)}(\lambda)

  • \text{CV}_{(k)}(\lambda) is the cross-validation error at \lambda.

The cross-validation error at \lambda is

\text{CV}_{(k)}(\lambda) = \frac{1}{k}\sum_{j=1}^{k}\text{MSE}_j(\lambda)

  • \text{MSE}_j(\lambda) is the error on fold j of a model fitted to the other k-1 folds at that \lambda (deviance or error rate for a GLM or classifier).

After tuning, the model is refit on all the training data at the chosen value.

Each hyperparameter moves the model along the bias-variance tradeoff. A larger \lambda or \alpha, a smaller d in boosting or a larger K in K-nearest neighbors means less flexibility, more bias and less variance.

The one-standard-error rule

The one-standard-error rule takes the simplest model whose cross-validation error is within one standard error of the minimum. For a penalty that is the largest such \lambda,

\hat{\lambda}_{\text{1SE}} = \max\left\{\lambda : \text{CV}(\lambda) \le \text{CV}(\hat{\lambda}) + \text{SE}(\hat{\lambda})\right\}

  • \text{SE}(\hat{\lambda}) is the standard error of the cross-validation error at \hat{\lambda}.

Which \lambda do minimum CV error and the one-standard-error rule choose for this lasso? A Poisson lasso for auto claim frequency is fitted over a grid of \lambda. Ten-fold cross-validation gives:

\lambda CV deviance SE Nonzero coefficients
0.001 104.8 2.3 18
0.01 102.1 2.2 14
0.05 101.0 2.0 9
0.10 102.6 2.1 6
0.20 104.3 2.4 4
0.50 109.5 2.8 2

Answer

  • The minimum CV deviance is 101.0, at \lambda = 0.05.
  • The one-standard-error threshold is 101.0 + 2.0 = 103.0.
  • The values of \lambda with CV deviance at most 103.0 are 0.01, 0.05 and 0.10. At \lambda = 0.20 it is 104.3.
  • The rule takes the largest, \lambda = 0.10, with 6 rating variables against 9 at the minimum.

Hyperparameters of tree ensembles

SRM asks for the hyperparameters that control the tree ensembles:

Method Hyperparameters
Bagging the number of trees B
Random Forest B and m, typically m \approx \sqrt{p} (m = p is bagging)
Boosting B, the shrinkage \lambda and the interaction depth d

In bagging and random forests B is not critical, since a large B does not overfit. In boosting too many trees can overfit, so B is chosen by cross-validation. A small shrinkage, such as \lambda = 0.01 or 0.001, needs a larger B, and d = 1 (stumps) often works well.

With p = 12 predictors, what m does a random forest typically use, and what is the model with m = 12?

  • A random forest typically uses m \approx \sqrt{12} = 3.46, so 3 or 4 predictors per split.
  • With m = 12 = p every predictor is available at every split: that is bagging.
  • Its trees are more correlated, so averaging them reduces variance less.

Hyperparameters of regularized regression

Ridge and lasso tune \lambda, after standardizing the predictors. The elastic net also tunes the mixing weight, alpha in R's glmnet, where alpha = 1 is the lasso and alpha = 0 ridge. It is a different quantity from the \alpha of cost-complexity pruning, which is a penalty per terminal node.

Tuning on the test set Choosing \lambda by test-set error and then reporting that error as the model's performance is optimistic, because the test set has been used to fit. Tune by cross-validation on the training data, and use the test set once.

Practice questions

Actuarial Notes