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

3.9 Multi-response Gaussian (grouped)🔗ℹ

The multi-response Gaussian family fits several numeric responses at once. The response Y is a matrix (one column per response), and the model applies a grouped lasso across the responses: a predictor enters or leaves for all responses together, so the fitted coefficient rows share support. Each response keeps its own intercept, and the fit is a plain identity-link Gaussian, so prediction is ŷr = a0r + x·βr.

In the data below both responses depend on x₁ (response 1 rises with it, response 2 falls) while x₂ carries no signal. The grouped lasso recovers the opposite signs and drives the entire x₂ row to 0.0 across both responses.

(require glmnet)

(provide run-example)

<data> ::=
(define X '((1.0 2.0) (2.0 1.0) (3.0 2.0) (4.0 1.0) (5.0 2.0) (6.0 1.0)))
; two responses: y1 = 1 + 2*x1, y2 = 10 - x1
(define Y '((3.0 9.0) (5.0 8.0) (7.0 7.0) (9.0 6.0) (11.0 5.0) (13.0 4.0)))

mgaussian-fit takes the predictor matrix and the response matrix and returns a mgaussian-result whose mgaussian-result-coefficients is a vector of per-response coefficient vectors. The x₁ coefficient is positive for response 1 and negative for response 2; the x₂ coefficients are exactly 0.0 for both.

<fit> ::=

(define result (mgaussian-fit X Y #:lambda 0.1))

mgaussian-predict returns the per-response predictions for each row:

(mgaussian-predict result X)
; => one (y1 y2) pair per row, tracking Y

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

<*> ::=