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

ElasticNet

Regressor sklearn-compatible 📈 Linear

ElasticNet — combined L1 + L2 regularisation via coordinate descent. / ElasticNet — régularisation combinée L1 + L2 par descente de coordonnées.

⚡ Rust-native ✓ sklearn parity
Quick start — Python
import seraplot as sp, numpy as np
X = np.random.randn(300, 8)
y = X[:, 0] - X[:, 2] * 0.5 + np.random.randn(300) * 0.4
model = sp.ElasticNet(alpha=0.5, l1_ratio=0.7)
model.fit(X, y)
print(model.score(X, y))
💡
EN — Drop-in replacement: sp.ElasticNet has the same API as sklearn.
FR — Remplacement direct : même API que sklearn, changez l'import.

API Reference

JSON function name

ml_elastic_net — aliases: elastic_net, elasticnet

Python class
sp.ElasticNet(alpha=1.0, l1_ratio=0.5, max_iter=1000, tol=1e-4, fit_intercept=true)
Constructor Parameters
ParameterTypeDefaultDescription
alphafloat1.0Overall regularisation strength.
l1_ratiofloat0.5L1 mix (0 = Ridge, 1 = Lasso).
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\rho|\beta|_1 + \frac{\alpha(1-\rho)}{2}|\beta|_2^2$$

Example
import seraplot as sp, numpy as np
X = np.random.randn(300, 8)
y = X[:, 0] - X[:, 2] * 0.5 + np.random.randn(300) * 0.4
model = sp.ElasticNet(alpha=0.5, l1_ratio=0.7)
model.fit(X, y)
print(model.score(X, y))

Référence API

Nom de fonction JSON

ml_elastic_net — alias : elastic_net, elasticnet

Classe Python
sp.ElasticNet(alpha=1.0, l1_ratio=0.5, max_iter=1000, tol=1e-4, fit_intercept=true)
Paramètres du constructeur
ParamètreTypeDéfautDescription
alphafloat1.0Force globale de régularisation.
l1_ratiofloat0.5Mix L1 (0 = Ridge, 1 = Lasso).
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\rho|\beta|_1 + \frac{\alpha(1-\rho)}{2}|\beta|_2^2$$

Exemple
import seraplot as sp, numpy as np
X = np.random.randn(300, 8)
y = X[:, 0] - X[:, 2] * 0.5 + np.random.randn(300) * 0.4
model = sp.ElasticNet(alpha=0.5, l1_ratio=0.7)
model.fit(X, y)
print(model.score(X, y))