Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Lasso

Regressor sklearn-compatible 📈 Linear

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: 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
ParameterTypeDefaultDescription
alphafloat1.0L1 regularisation strength.
max_iterint1000Maximum iterations.
tolfloat1e-4Convergence tolerance.
fit_interceptbooltrueFit 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ètreTypeDéfautDescription
alphafloat1.0Force de régularisation L1.
max_iterint1000Nombre maximum d'itérations.
tolfloat1e-4Tolérance de convergence.
fit_interceptbooltrueAjuster 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_])