The Lasso

Today

  • Delivery times
  • Lasso
    • Penalized criterion
    • Constraint regions
    • Soft thresholding
    • Estimate path
  • Tuning parameter selection
    • Cross-validation
    • Test evaluation
    • Lasso estimates
  • Repeated training samples
    • Test MSE
    • Selected sets

Delivery times

  • Question: does a model that keeps only some of the 35 features predict delivery times better than one that uses all of them?
  • Response variable: time_to_delivery, in minutes
  • Explanatory variables: hour, day, distance, item_01, …, item_27
  • Training orders: 100, the ridge lecture’s sample
  • Test orders: 9,912, the ridge lecture’s test orders

Data

Ridge estimates

Lasso

Two features

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\left|\beta_j\right| = RSS + \lambda\sum_{j=1}^p\left|\beta_j\right|\]

  • \(\tilde x_{ij}\) — feature \(j\) of order \(i\), standardized
  • \(\lambda \ge 0\) — tuning parameter
  • \(\lambda\sum_{j=1}^p\left|\beta_j\right|\) — \(\ell_1\) penalty; ridge: \(\ell_2\) penalty \(\lambda\sum_{j=1}^p\beta_j^2\)
  • \(\beta_0\) — intercept, not penalized

Maximum lambda

\[\lambda \ge \lambda_{\max} = \max_{j}\, 2\left|\sum_{i=1}^n\tilde x_{ij}\left(y_i - \bar y\right)\right|\]

  • \(\lambda = 0\): least squares
  • \(\lambda \ge \lambda_{\max}\): \(\widehat\beta_0 = \bar y\) and every slope estimate is zero, the null model
  • Training orders: \(\lambda_{\max} = 967.4\), set by hour

Constraint regions

Minimize the RSS subject to

\[\sum_{j=1}^p\left|\beta_j\right| \le s, \qquad\text{and for ridge regression}\qquad \sum_{j=1}^p\beta_j^2 \le s\]

  • \(s \ge 0\) — budget
  • smaller \(\lambda\), larger \(s\)

Constraint regions, two features

Best subset selection

\[\sum_{j=1}^p\mathrm{I}\left(\beta_j \ne 0\right) \le s\]

  • \(\sum_j\mathrm{I}\left(\beta_j \ne 0\right)\) — number of nonzero coefficients, the \(\ell_0\) penalty
  • lasso: a convex relaxation

Soft thresholding

Orthogonal standardized features: \(\tilde{\mathbf{X}}^\top\tilde{\mathbf{X}} = n\mathbf{I}_p\)

\[\widehat\beta^L_{\lambda j} = \text{sign}\left(\widehat\beta_j\right)\left(\left|\widehat\beta_j\right| - \frac{\lambda}{2n}\right)_+, \qquad \widehat\beta^R_{\lambda j} = \frac{n}{n + \lambda}\widehat\beta_j\]

  • \(\widehat\beta_j\) — least squares estimate
  • \(\widehat\beta^L_{\lambda j}\) — lasso estimate
  • \(\widehat\beta^R_{\lambda j}\) — ridge estimate
  • \((u)_+ = \max(u, 0)\)
  • \(\lambda/(2n)\) — threshold

Lasso and ridge estimates

glmnet scaling

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

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

  • \(\lambda_{\text{glmnet}}\) — the value glmnet() calls lambda
  • no \(s_y\), unlike ridge regression’s \(\lambda = n\lambda_{\text{glmnet}}/s_y\)

Estimate path

Tuning parameter selection

Cross-validation

Test evaluation

Method \(\lambda\) Nonzero estimates Training MSE 10-fold CV estimate Test MSE
Least squares 0 35 10.13 29.23 22.02
Ridge 28.2 35 12.23 24.57 20.38
Lasso 89.1 14 13.78 20.20 16.96

Lasso estimates

Interpretation

  • Intercept, original scale: \(\widehat\beta_0 = -10.5\) minutes, for a Monday order at hour 0, distance 0, no items
  • Hour: 1.76 minutes per hour (ridge 1.46, least squares 1.87)
  • Distance: 2.37 minutes per mile (ridge 2.19, least squares 2.79)
  • Day: keeps Tue, Fri, Sat; drops Wed, Thu, Sun, predicted like Monday
  • Items: keeps 9 of 27, minutes per additional unit of the item
  • Nonzero lasso estimates are shrunken toward zero
  • lm() standard errors and \(p\)-values do not apply

Repeated training samples

Test MSE

Average over samples

  • \(n = 100\): the lasso has the lower MSE than least squares in 94% of the samples; its average MSE is 15.0% below
  • \(n = 300\): the lasso has the lower MSE in 56% of the samples; its average MSE is 0.6% above least squares

Selected sets

Estimator bias

Conclusion

  • The lasso penalizes absolute coefficients, so some estimates are exactly zero
  • Soft thresholding shrinks estimates and zeroes the small ones
  • Choose \(\lambda\) by cross-validation; evaluate once on test data
  • Lasso versus ridge depends on how many features matter
  • The selected set is unstable and the lasso estimator is biased toward zero