SgdClassifier
SGDClassifier — stochastic gradient descent for linear classifiers. / SGDClassifier — descente de gradient stochastique pour classifieurs linéaires.
import seraplot as sp, numpy as np
X = np.random.randn(1000, 5)
y = (X[:, 0] > 0).astype(int)
clf = sp.SGDClassifier(loss="hinge", alpha=1e-4)
clf.fit(X, y)
print(clf.score(X, y))
sp.SgdClassifier has the same API as sklearn.FR — Remplacement direct : même API que sklearn, changez l'import.
API Reference
ml_sgd_classifier — aliases: sgd_classifier, sgd_cls
sp.SgdClassifier(loss=hinge, alpha=0.0001, max_iter=1000, tol=1e-3, eta0=1.0, fit_intercept=true)
| Parameter | Type | Default | Description |
|---|---|---|---|
loss | str | hinge | Loss: `hinge`, `log`, `modified_huber`, `squared_hinge`. |
alpha | float | 0.0001 | Regularisation multiplier. |
max_iter | int | 1000 | Maximum passes over the data. |
tol | float | 1e-3 | Convergence tolerance. |
eta0 | float | 1.0 | Initial learning rate. |
fit_intercept | bool | true | Fit an intercept term. |
JSON with predictions, coef, intercept.
$$\beta_{t+1} = \beta_t - \eta_t \nabla_{\beta} L(y_i, x_i^T\beta_t)$$
import seraplot as sp, numpy as np
X = np.random.randn(1000, 5)
y = (X[:, 0] > 0).astype(int)
clf = sp.SGDClassifier(loss="hinge", alpha=1e-4)
clf.fit(X, y)
print(clf.score(X, y))
Référence API
ml_sgd_classifier — alias : sgd_classifier, sgd_cls
sp.SgdClassifier(loss=hinge, alpha=0.0001, max_iter=1000, tol=1e-3, eta0=1.0, fit_intercept=true)
| Paramètre | Type | Défaut | Description |
|---|---|---|---|
loss | str | hinge | Perte : `hinge`, `log`, `modified_huber`, `squared_hinge`. |
alpha | float | 0.0001 | Multiplicateur de régularisation. |
max_iter | int | 1000 | Nombre maximum de passes sur les données. |
tol | float | 1e-3 | Tolérance de convergence. |
eta0 | float | 1.0 | Taux d'apprentissage initial. |
fit_intercept | bool | true | Ajuster un terme d'intercept. |
JSON avec predictions, coef, intercept.
$$\beta_{t+1} = \beta_t - \eta_t \nabla_{\beta} L(y_i, x_i^T\beta_t)$$
import seraplot as sp, numpy as np
X = np.random.randn(1000, 5)
y = (X[:, 0] > 0).astype(int)
clf = sp.SGDClassifier(loss="hinge", alpha=1e-4)
clf.fit(X, y)
print(clf.score(X, y))
SgdRegressor
SGDRegressor — stochastic gradient descent for linear regressors. / SGDRegressor — descente de gradient stochastique pour régresseurs linéaires.
import seraplot as sp, numpy as np
X = np.random.randn(1000, 3)
y = X @ [1.5, -0.5, 2.0] + np.random.randn(1000) * 0.5
reg = sp.SGDRegressor(alpha=1e-4, max_iter=500)
reg.fit(X, y)
print(reg.score(X, y))
sp.SgdRegressor has the same API as sklearn.FR — Remplacement direct : même API que sklearn, changez l'import.
API Reference
ml_sgd_regressor — aliases: sgd_regressor, sgd_reg
sp.SgdRegressor(alpha=0.0001, max_iter=1000, tol=1e-3, eta0=0.1, fit_intercept=true)
| Parameter | Type | Default | Description |
|---|---|---|---|
alpha | float | 0.0001 | Regularisation multiplier. |
max_iter | int | 1000 | Maximum passes. |
tol | float | 1e-3 | Convergence tolerance. |
eta0 | float | 0.1 | Initial learning rate. |
fit_intercept | bool | true | Fit an intercept. |
JSON with predictions, coef, intercept.
$$\beta_{t+1} = \beta_t - \eta_t \cdot 2(\hat{y}_i - y_i) x_i$$
import seraplot as sp, numpy as np
X = np.random.randn(1000, 3)
y = X @ [1.5, -0.5, 2.0] + np.random.randn(1000) * 0.5
reg = sp.SGDRegressor(alpha=1e-4, max_iter=500)
reg.fit(X, y)
print(reg.score(X, y))
Référence API
ml_sgd_regressor — alias : sgd_regressor, sgd_reg
sp.SgdRegressor(alpha=0.0001, max_iter=1000, tol=1e-3, eta0=0.1, fit_intercept=true)
| Paramètre | Type | Défaut | Description |
|---|---|---|---|
alpha | float | 0.0001 | Multiplicateur de régularisation. |
max_iter | int | 1000 | Nombre maximum de passes. |
tol | float | 1e-3 | Tolérance de convergence. |
eta0 | float | 0.1 | Taux d'apprentissage initial. |
fit_intercept | bool | true | Ajuster un intercept. |
JSON avec predictions, coef, intercept.
$$\beta_{t+1} = \beta_t - \eta_t \cdot 2(\hat{y}_i - y_i) x_i$$
import seraplot as sp, numpy as np
X = np.random.randn(1000, 3)
y = X @ [1.5, -0.5, 2.0] + np.random.randn(1000) * 0.5
reg = sp.SGDRegressor(alpha=1e-4, max_iter=500)
reg.fit(X, y)
print(reg.score(X, y))