On this page:
<require>
<provide>
<data>
<fit>
<run-example>
<*>

3.3 Lasso (L1, α = 1)🔗

The lasso is the elastic net at α = 1: a pure L1 penalty. Where ridge shrinks every coefficient but keeps them all, the lasso performs variable selection it drives coefficients exactly to zero, and more of them as λ grows. It is the model you reach for when you believe only a few predictors matter and you want the fit to say which.

Using the same fixture — relevant x₁, x₂ and the irrelevant x₃ = x₁² a modest λ selects x₃ out entirely (its coefficient is 0.0) while keeping the two real predictors. Push λ higher and even x₂ drops, until at large λ only the intercept survives.

(require glmnet)

(provide run-example)

<data> ::=
(define X '((1.0 2.0  1.0)
            (2.0 1.0  4.0)
            (3.0 4.0  9.0)
            (4.0 3.0 16.0)
            (5.0 6.0 25.0)
            (6.0 5.0 36.0)))
(define y '(1.0 4.0 3.0 6.0 5.0 8.0))

lasso is elnet-fit with #:alpha 1.0. The third coefficient comes back exactly 0.0 the irrelevant predictor has been selected out.

<fit> ::=

(define result (lasso X y #:lambda 0.05))

(define (run-example)
  <data>
  <fit>
  result)

<*> ::=