Lasso
Lasso regression — L1-penalised OLS via coordinate descent. / Régression Lasso — OLS pénalisée L1 par descente de coordonnées.
⚡ Rust-native
✓ sklearn parity
Quick start — Python
import seraplot as sp, numpy as np
X = np.random.randn(200, 10)
y = X[:, 0] * 2 + X[:, 3] * -1.5 + np.random.randn(200) * 0.3
model = sp.Lasso(alpha=0.1)
model.fit(X, y)
print([f"{c:.3f}" for c in model.coef_])
EN — Drop-in replacement:
FR — Remplacement direct : même API que sklearn, changez l'import.
sp.Lasso has the same API as sklearn.FR — Remplacement direct : même API que sklearn, changez l'import.
API Reference
JSON function name
ml_lasso — aliases: lasso
Python class
sp.Lasso(alpha=1.0, max_iter=1000, tol=1e-4, fit_intercept=true)
Constructor Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
alpha | float | 1.0 | L1 regularisation strength. |
max_iter | int | 1000 | Maximum iterations. |
tol | float | 1e-4 | Convergence tolerance. |
fit_intercept | bool | true | Fit an intercept term. |
Returns
JSON with predictions, coef, intercept.
Algorithm
$$\hat{\beta} = \arg\min_{\beta}|y - X\beta|_2^2 + \alpha|\beta|_1$$
Example
import seraplot as sp, numpy as np
X = np.random.randn(200, 10)
y = X[:, 0] * 2 + X[:, 3] * -1.5 + np.random.randn(200) * 0.3
model = sp.Lasso(alpha=0.1)
model.fit(X, y)
print([f"{c:.3f}" for c in model.coef_])
Référence API
Nom de fonction JSON
ml_lasso — alias : lasso
Classe Python
sp.Lasso(alpha=1.0, max_iter=1000, tol=1e-4, fit_intercept=true)
Paramètres du constructeur
| Paramètre | Type | Défaut | Description |
|---|---|---|---|
alpha | float | 1.0 | Force de régularisation L1. |
max_iter | int | 1000 | Nombre maximum d'itérations. |
tol | float | 1e-4 | Tolérance de convergence. |
fit_intercept | bool | true | Ajuster un terme d'intercept. |
Retourne
JSON avec predictions, coef, intercept.
Algorithme
$$\hat{\beta} = \arg\min_{\beta}|y - X\beta|_2^2 + \alpha|\beta|_1$$
Exemple
import seraplot as sp, numpy as np
X = np.random.randn(200, 10)
y = X[:, 0] * 2 + X[:, 3] * -1.5 + np.random.randn(200) * 0.3
model = sp.Lasso(alpha=0.1)
model.fit(X, y)
print([f"{c:.3f}" for c in model.coef_])