Linear regression
A Gaussian linear model estimates a real-valued conditional mean. With a complete penalty R, its objective is
β0,βmin2n∥y−β01−Xβ∥22+R(β). 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.