Shrinkage

Linear regression

A Gaussian linear model estimates a real-valued conditional mean. With a complete penalty RR, its objective is

min⁡β0,β  ∥y−β01−X~β∥222n+R(β). \min_{\beta_0,\beta}\;\frac{\|y - \beta_0\mathbf{1} - \widetilde X\beta\|_2^2}{2n} + R(\beta).

Choose L1 for sparsity, ridge for quadratic shrinkage, or another compatible penalty. The response must contain one finite real value per observation.

Fit an elastic net

use faer::{Col, Mat};
use shrinkage::{ElasticNet, Gaussian, Problem, ProximalGradient, Termination};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let x = Mat::from_fn(6, 2, |i, j| if j == 0 { i as f64 } else { (i % 2) as f64 });
    let y = [1.0, 3.0, 4.0, 7.0, 8.0, 11.0];
    let fit = Problem::new(&x, Gaussian::new(&y), ElasticNet::new(0.1, 0.2))
        .fit_with(&ProximalGradient::<Col<f64>>::new())?;
    assert_eq!(fit.termination(), Termination::Converged);
    println!("Original-scale coefficients: {:?}", fit.coefficients());
    println!("Response means: {:?}", fit.predict(&x)?);
    Ok(())
}

The default fits an unpenalized intercept and standardizes features using training statistics. See normalization to change these modeling choices.

For Gaussian L1 problems, coordinate descent and the Lasso builder provide a specialized implementation. IRLS also supports separable penalties; the hybrid solver handles supported fusion and SLOPE models. The compatibility table lists the available combinations.