# L1 (lasso)

The L1 penalty sets individual coefficients exactly to zero. Its diamond-shaped constraint region has corners on the coordinate axes, which favor sparse solutions. At zero strength, the penalty vanishes. 

$$

  R(\beta) = \lambda\sum_{j=1}^p|\beta_j|.

$$

<a id="constraint-region"></a>

## Constraint region

![Feasible region for l1 (lasso); the shaded set includes its boundary.](<../assets/dedff98caeb309b7f500fc5ac2ba08edd0b439f4c8df50b3b48c729f284502be.svg>) 

$\lambda = 1$: $|\beta_1| + |\beta_2| \leq 1$. See the [plot conventions](<./#read-the-constraint-plots>) for the fixed budget and coefficient scale. 

<a id="use-the-penalty"></a>

## Use the penalty

```rust
use shrinkage::{L1, Penalty, ProximalPenalty};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let penalty = L1::new(0.5);
    let coefficients = [2.0, -1.0];
    println!("Penalty: {}", penalty.value(&coefficients)?);
    let mut shrunk = [0.0; 2];
    penalty.prox(&coefficients, 1.0, &mut shrunk)?;
    println!("Proximal result: {shrunk:?}");
    Ok(())
}
```

Use [coordinate descent](<../reference/solvers/coordinate-descent>) for Gaussian lasso, [IRLS](<../reference/solvers/irls>) for Gaussian or binomial datafits, or [proximal gradient](<../reference/solvers/proximal-gradient>). The exact proximal map is soft-thresholding at the step size times the strength. The named [Lasso model](<../models/lasso>) provides the Gaussian convenience API. 

API: [`shrinkage::L1`](<https://shrinkage.cc/packages/rust/reference/d68834a1b760d86f3b5ee835f77535148f4e2cb3f2e1f19663a1cc42f9808935>).
