# shrinkage.Lasso

Shrinkage for Python · 0.2.0

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/packages/python/src/shrinkage/lasso.py>)

<a id="constructor"></a>

```python
Lasso(
    lambda_: float,
    *,
    fit_intercept: bool = True,
    normalization: shrinkage.Normalization = "auto",
    stopping: StoppingCriterion | None = None,
    max_iterations: int = 10000
)
```

Configure Gaussian lasso, then call [`fit`](<72117a8837149fd66fd98093cc15a966b8ba732b3859e6f1dc370d0fa3458085#fit>) for an owned result.

Minimize `P(beta_0, beta) = F(beta_0, beta) + R(beta)`, where `F = ||y - X_tilde @ beta - beta_0||**2 / (2*n)` and `R = lambda_ * ||beta||_1`. The intercept is unpenalized. `lambda_` must be finite and nonnegative. `normalization="auto"` divides columns by population standard deviations and centers by their means when `fit_intercept=True`. Other presets are independent of the intercept setting. Penalties act on normalized coefficients; results and predictions use the original input scale.

By default, positive penalties use relative duality gap `1e-6` and zero penalty uses absolute KKT violation `1e-6`. `stopping` overrides this choice. `max_iterations` limits complete sweeps over the current working set and must be positive. Full convergence checks run at initialization, every ten sweeps, and at the iteration limit. Options are validated when fitting.

<a id="lambda_"></a>

## `lambda_`

```python
lambda_: float
```

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/packages/python/src/shrinkage/lasso.py>)

<a id="fit_intercept"></a>

## `fit_intercept`

```python
fit_intercept: bool = field(default=True, kw_only=True)
```

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/packages/python/src/shrinkage/lasso.py>)

<a id="normalization"></a>

## `normalization`

```python
normalization: shrinkage.Normalization = field(default="auto", kw_only=True)
```

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/packages/python/src/shrinkage/lasso.py>)

<a id="stopping"></a>

## `stopping`

```python
stopping: StoppingCriterion | None = field(default=None, kw_only=True)
```

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/packages/python/src/shrinkage/lasso.py>)

<a id="max_iterations"></a>

## `max_iterations`

```python
max_iterations: int = field(default=10_000, kw_only=True)
```

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/packages/python/src/shrinkage/lasso.py>)

<a id="fit"></a>

## `fit`

```python
fit(x: object, y: object, *, copy: bool = True) -> shrinkage.LassoFit
```

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/packages/python/src/shrinkage/lasso.py>)

Fit exact NumPy float64 arrays of shapes `(n, p)` and `(n,)`.

Strided, writable, and read-only arrays are supported. Both inputs are copied into Rust-owned storage with the GIL held. Callers must prevent concurrent mutation or resizing until copying finishes. Numerical fitting releases the GIL and calls no Python callbacks. `copy=False` raises `ValueError`.

Invalid data or options raise `TypeError` or `ValueError`. Nonfinite arithmetic from finite inputs raises `FloatingPointError`. An exhausted budget returns a fit with termination `"iteration_limit"`.
