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

3.1 Ordinary least squares (λ = 0)🔗

The elastic net at penalty strength λ = 0 is just ordinary least squares: with no penalty, the mixing parameter α drops out and glmnet returns the unregularized fit. It is the natural first model — a known answer we can check exactly.

We use a noise-free fixture so the answer is unambiguous. Take two predictors and build the response as an exact linear function of them, y = 1 + 2 x₁ − x₂, with no error term. Ordinary least squares then recovers the intercept 1.0 and coefficients (2.0 -1.0) up to the coordinate-descent solver’s tolerance — with R² ≈ 1.

(require glmnet)

(provide run-example)

The design matrix is a list of rows; the response is the matching vector. (Rows here, columns there: the binding marshals to the column-major layout the Fortran expects.)

<data> ::=
(define X '((1.0 2.0)
            (2.0 1.0)
            (3.0 4.0)
            (4.0 3.0)
            (5.0 6.0)))
(define y '(1.0 4.0 3.0 6.0 5.0))

ols is elnet-fit with #:lambda 0.0. The result is an elnet-result carrying the intercept, the dense coefficient vector, the achieved , and the λ actually used.

<fit> ::=

(define result (ols X y))

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

<*> ::=