ElasticNet
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:
FR — Remplacement direct : même API que sklearn, changez l'import.
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
| Parameter | Type | Default | Description |
|---|---|---|---|
alpha | float | 1.0 | Overall regularisation strength. |
l1_ratio | float | 0.5 | L1 mix (0 = Ridge, 1 = Lasso). |
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\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ètre | Type | Défaut | Description |
|---|---|---|---|
alpha | float | 1.0 | Force globale de régularisation. |
l1_ratio | float | 0.5 | Mix L1 (0 = Ridge, 1 = Lasso). |
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\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))