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

LogisticRegression

Classifier sklearn-compatible 📈 Linear

Logistic regression — L2-regularised binary/multiclass via Newton-CG. / Régression logistique — binaire/multi-classe L2 via Newton-CG.

⚡ Rust-native ✓ sklearn parity
Quick start — Python
import seraplot as sp, numpy as np
X = np.random.randn(400, 4)
y = (X[:, 0] + X[:, 1] > 0).astype(int)
model = sp.LogisticRegression(C=1.0)
model.fit(X, y)
print(f"Accuracy: {model.score(X, y):.3f}")
💡
EN — Drop-in replacement: sp.LogisticRegression has the same API as sklearn.
FR — Remplacement direct : même API que sklearn, changez l'import.

API Reference

JSON function name

ml_logistic_regression — aliases: logistic_regression, logistic

Python class
sp.LogisticRegression(C=1.0, max_iter=100, tol=1e-4, fit_intercept=true)
Constructor Parameters
ParameterTypeDefaultDescription
Cfloat1.0Inverse regularisation strength (larger = less reg).
max_iterint100Maximum iterations.
tolfloat1e-4Convergence tolerance.
fit_interceptbooltrueFit an intercept term.
Returns

JSON with predictions, coef, intercept, classes.

Algorithm

$$P(y=1|x) = \sigma(x^T\beta + b), \quad \sigma(z) = \frac{1}{1+e^{-z}}$$

Example
import seraplot as sp, numpy as np
X = np.random.randn(400, 4)
y = (X[:, 0] + X[:, 1] > 0).astype(int)
model = sp.LogisticRegression(C=1.0)
model.fit(X, y)
print(f"Accuracy: {model.score(X, y):.3f}")

Référence API

Nom de fonction JSON

ml_logistic_regression — alias : logistic_regression, logistic

Classe Python
sp.LogisticRegression(C=1.0, max_iter=100, tol=1e-4, fit_intercept=true)
Paramètres du constructeur
ParamètreTypeDéfautDescription
Cfloat1.0Force de régularisation inverse (plus grand = moins de régul.).
max_iterint100Nombre maximum d'itérations.
tolfloat1e-4Tolérance de convergence.
fit_interceptbooltrueAjuster un terme d'intercept.
Retourne

JSON avec predictions, coef, intercept, classes.

Algorithme

$$P(y=1|x) = \sigma(x^T\beta + b), \quad \sigma(z) = \frac{1}{1+e^{-z}}$$

Exemple
import seraplot as sp, numpy as np
X = np.random.randn(400, 4)
y = (X[:, 0] + X[:, 1] > 0).astype(int)
model = sp.LogisticRegression(C=1.0)
model.fit(X, y)
print(f"Précision : {model.score(X, y):.3f}")