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

SgdClassifier

Classifier sklearn-compatible 📈 Linear

SGDClassifier — stochastic gradient descent for linear classifiers. / SGDClassifier — descente de gradient stochastique pour classifieurs linéaires.

⚡ Rust-native ✓ sklearn parity
Quick start — Python
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))
💡
EN — Drop-in replacement: sp.SgdClassifier has the same API as sklearn.
FR — Remplacement direct : même API que sklearn, changez l'import.

API Reference

JSON function name

ml_sgd_classifier — aliases: sgd_classifier, sgd_cls

Python class
sp.SgdClassifier(loss=hinge, alpha=0.0001, max_iter=1000, tol=1e-3, eta0=1.0, fit_intercept=true)
Constructor Parameters
ParameterTypeDefaultDescription
lossstrhingeLoss: `hinge`, `log`, `modified_huber`, `squared_hinge`.
alphafloat0.0001Regularisation multiplier.
max_iterint1000Maximum passes over the data.
tolfloat1e-3Convergence tolerance.
eta0float1.0Initial learning rate.
fit_interceptbooltrueFit an intercept term.
Returns

JSON with predictions, coef, intercept.

Algorithm

$$\beta_{t+1} = \beta_t - \eta_t \nabla_{\beta} L(y_i, x_i^T\beta_t)$$

Example
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

Nom de fonction JSON

ml_sgd_classifier — alias : sgd_classifier, sgd_cls

Classe Python
sp.SgdClassifier(loss=hinge, alpha=0.0001, max_iter=1000, tol=1e-3, eta0=1.0, fit_intercept=true)
Paramètres du constructeur
ParamètreTypeDéfautDescription
lossstrhingePerte : `hinge`, `log`, `modified_huber`, `squared_hinge`.
alphafloat0.0001Multiplicateur de régularisation.
max_iterint1000Nombre maximum de passes sur les données.
tolfloat1e-3Tolérance de convergence.
eta0float1.0Taux d'apprentissage initial.
fit_interceptbooltrueAjuster un terme d'intercept.
Retourne

JSON avec predictions, coef, intercept.

Algorithme

$$\beta_{t+1} = \beta_t - \eta_t \nabla_{\beta} L(y_i, x_i^T\beta_t)$$

Exemple
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

Regressor sklearn-compatible 📈 Linear

SGDRegressor — stochastic gradient descent for linear regressors. / SGDRegressor — descente de gradient stochastique pour régresseurs linéaires.

⚡ Rust-native ✓ sklearn parity
Quick start — Python
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))
💡
EN — Drop-in replacement: sp.SgdRegressor has the same API as sklearn.
FR — Remplacement direct : même API que sklearn, changez l'import.

API Reference

JSON function name

ml_sgd_regressor — aliases: sgd_regressor, sgd_reg

Python class
sp.SgdRegressor(alpha=0.0001, max_iter=1000, tol=1e-3, eta0=0.1, fit_intercept=true)
Constructor Parameters
ParameterTypeDefaultDescription
alphafloat0.0001Regularisation multiplier.
max_iterint1000Maximum passes.
tolfloat1e-3Convergence tolerance.
eta0float0.1Initial learning rate.
fit_interceptbooltrueFit an intercept.
Returns

JSON with predictions, coef, intercept.

Algorithm

$$\beta_{t+1} = \beta_t - \eta_t \cdot 2(\hat{y}_i - y_i) x_i$$

Example
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

Nom de fonction JSON

ml_sgd_regressor — alias : sgd_regressor, sgd_reg

Classe Python
sp.SgdRegressor(alpha=0.0001, max_iter=1000, tol=1e-3, eta0=0.1, fit_intercept=true)
Paramètres du constructeur
ParamètreTypeDéfautDescription
alphafloat0.0001Multiplicateur de régularisation.
max_iterint1000Nombre maximum de passes.
tolfloat1e-3Tolérance de convergence.
eta0float0.1Taux d'apprentissage initial.
fit_interceptbooltrueAjuster un intercept.
Retourne

JSON avec predictions, coef, intercept.

Algorithme

$$\beta_{t+1} = \beta_t - \eta_t \cdot 2(\hat{y}_i - y_i) x_i$$

Exemple
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))