Big models. Small coefficients.

Fit regularized statistical models with a Rust numerical core. Start with lasso, explore regularization paths, or compose a model from losses, penalties, and solvers.

- [Get started](<installation>)
- [Rust API](<packages/rust/>)
- [Python API](<packages/python/>)

## Models from reusable parts

Combine Gaussian, binomial, and multivariate Gaussian losses with compatible penalties and solvers. Extend the Rust API with your own components.

[Read more](<packages/rust/>)

## Dense and sparse matrices

Use faer, nalgebra, ndarray, or sparse CSC matrices. Enable the integrations you need through optional Rust features.

[Read more](<installation>)

## Compose models in Python

Fit Gaussian and logistic models from NumPy arrays with explicit hybrid or proximal-gradient solvers, and inspect predictions and convergence.

[Read more](<packages/python/>)

# Shrinkage

<a id="explore-regularization"></a>

## Explore regularization

![Gaussian loss contours overlaid with the L1 penalty region, alongside contours of the penalized objective.](<assets/6f7f40b0553526ae84a287c4d3f265de34ee953862a3c02e9532a491ffa04535.svg>) 

Combine a [datafit](<datafits/>), a [penalty](<penalties/>), and a [compatible solver](<reference/solvers/>) to explore a two-coefficient model. Enable JavaScript to adjust the problem and follow the solver toward its optimum. The penalty region uses the budget at the penalized optimum, showing the equivalent constrained problem. 

<a id="start-with-lasso"></a>

## Start with lasso

Fit a Gaussian lasso model with the Rust convenience API: 

```rust
use faer::Mat;
use shrinkage::Lasso;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let x = Mat::from_fn(3, 1, |i, _| i as f64);
    let y = [1.0, 3.0, 5.0];

    let fit = Lasso::new(0.1).fit(&x, &y)?;
    println!("Coefficients: {:?}", fit.coefficients());
    println!("Predictions: {:?}", fit.predict(&x)?);
    Ok(())
}
```

By default, `Lasso` fits an unpenalized intercept and standardizes features using training data. Returned coefficients use the original input scale, and prediction reuses the fitted preprocessing. Check `fit.termination()` to inspect convergence. 

Follow the [installation guide](<installation>) to enable the `faer` feature and run the example. Shrinkage is under development; the Rust and Python packages are available from source and have not yet been published to package registries. 

<a id="explore-further"></a>

## Explore further

Browse the Guide's [datafits](<datafits/>), [models](<models/>), and [penalties](<penalties/>) for mathematical definitions, constraint plots, and model examples. The [solver reference](<reference/solvers/>) compares supported compositions and convergence diagnostics. 

The Rust API supports regularization paths and penalties including lasso, ridge, elastic net, [SLOPE](<models/slope>), disjoint Group LASSO, [clustered lasso](<models/clustered-lasso>), and [chain fused lasso](<models/chain-fused-lasso>). SLOPE and both fusion penalties have dense Gaussian and logistic hybrid solvers. See the [Rust API reference](<https://shrinkage.cc/packages/rust/>) for supported combinations and the [statistical conventions](<https://github.com/jolars/shrinkage/blob/main/DESIGN.md>) for loss normalization, penalty scales, and intercept handling. 

The [Python API](<https://shrinkage.cc/packages/python/>) provides dense Gaussian lasso and compositional Gaussian and binomial fitting with clustered lasso, chain fused lasso, and SLOPE. Select hybrid or proximal gradient explicitly, predict on new observations, and inspect preprocessing and convergence diagnostics. Both packages share numerical implementations and statistical conventions, with independent versions and release schedules. 

To contribute, read the [contribution guide](<contributing>).
