Ridge Regression

Today

  • Delivery times
    • Data
    • Features
    • Least squares
  • Ridge regression
    • Item counts
    • Penalized criterion
    • Closed form
    • Estimate path
  • Bias-variance tradeoff
    • Prediction spread
    • Training sample size
  • Tuning parameter selection
    • Cross-validation
    • Test evaluation

Delivery times

  • Question: how long will a food delivery order take?
  • Response variable: time_to_delivery, in minutes
  • Explanatory variables: hour, day, distance, item_01, …, item_27
  • Training orders: 100, a small random sample
  • Test orders: 9,912, every other order

Data

Features

  • Features, \(p = 35\): hour, distance, 27 item counts, 6 day dummies
  • Reference level: Monday

Least squares

Ridge regression

Item counts

Penalized criterion

\[\sum_{i=1}^n\left(y_i - \beta_0 - \sum_{j=1}^p\beta_j\tilde x_{ij}\right)^2 + \lambda\sum_{j=1}^p\beta_j^2 = RSS + \lambda\sum_{j=1}^p\beta_j^2\]

  • \(\tilde x_{ij} = \left(x_{ij} - \bar x_j\right)/s_j\) — feature \(j\) of order \(i\), standardized
  • \(\lambda \ge 0\) — tuning parameter
  • \(\lambda\sum_{j=1}^p\beta_j^2\) — shrinkage penalty
  • \(\beta_0\) — intercept, not penalized

Closed form

\[\widehat\beta_0 = \bar y, \qquad \widehat\beta^R_\lambda = \left(\tilde{\mathbf{X}}^\top\tilde{\mathbf{X}} + \lambda\mathbf{I}_p\right)^{-1}\tilde{\mathbf{X}}^\top\left(y - \bar y\mathbf{1}\right)\]

  • \(\tilde{\mathbf{X}}\) — standardized features, without a column of ones
  • \(\mathbf{I}_p\) — \(p \times p\) identity matrix
  • \(\lambda = 0\): least squares
  • \(\lambda \to \infty\): \(\widehat\beta^R_\lambda \to 0\), the null model

glmnet scaling

\[\frac{1}{2n}RSS + \frac{\lambda_{\text{glmnet}}}{2}\sum_{j=1}^p\beta_j^2\]

\[\lambda = \frac{n\,\lambda_{\text{glmnet}}}{s_y}\]

  • \(\lambda_{\text{glmnet}}\) — the value glmnet() calls lambda
  • \(s_y\) — standard deviation of \(y\), divisor \(n\)

Estimate path

Bias-variance tradeoff

Prediction spread

Training sample size

Tuning parameter selection

Cross-validation

Test evaluation

Method \(\lambda\) Training MSE 10-fold CV estimate Test MSE
Least squares 0 10.13 29.23 22.02
Ridge 28.2 12.23 24.57 20.38

Conclusion

  • Ridge penalizes the squared coefficients, not the intercept
  • The ridge estimate has a closed form between least squares and the null model
  • Estimates shrink smoothly toward zero as \(\lambda\) grows, and none reaches it
  • The gain over least squares is largest for small training samples
  • Choose \(\lambda\) by cross-validation, evaluate once on test data