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

LinearSvc

Classifier sklearn-compatible ⚡ SVM

LinearSVC — linear Support Vector Machine for classification via dual coordinate descent. / LinearSVC — Machine à vecteurs de support linéaire pour classification.

⚡ Rust-native ✓ sklearn parity
Quick start — Python
import seraplot as sp
from sklearn.datasets import make_classification
X, y = make_classification(n_samples=500, n_features=8)
svc = sp.LinearSVC(C=1.0)
svc.fit(X, y)
print(svc.score(X, y))
💡
EN — Drop-in replacement: sp.LinearSvc has the same API as sklearn.
FR — Remplacement direct : même API que sklearn, changez l'import.

API Reference

JSON function name

ml_linear_svc — aliases: linear_svc

Python class
sp.LinearSvc(C=1.0, max_iter=1000, tol=1e-4)
Constructor Parameters
ParameterTypeDefaultDescription
Cfloat1.0Regularisation parameter (inverse margin).
max_iterint1000Maximum iterations.
tolfloat1e-4Convergence tolerance.
Returns

JSON with predictions.

Algorithm

$$\min_{w,b}\frac{1}{2}|w|^2 + C\sum_i \max(0, 1 - y_i(w^Tx_i + b))$$

Example
import seraplot as sp
from sklearn.datasets import make_classification
X, y = make_classification(n_samples=500, n_features=8)
svc = sp.LinearSVC(C=1.0)
svc.fit(X, y)
print(svc.score(X, y))

Référence API

Nom de fonction JSON

ml_linear_svc — alias : linear_svc

Classe Python
sp.LinearSvc(C=1.0, max_iter=1000, tol=1e-4)
Paramètres du constructeur
ParamètreTypeDéfautDescription
Cfloat1.0Paramètre de régularisation (inverse de la marge).
max_iterint1000Nombre maximum d'itérations.
tolfloat1e-4Tolérance de convergence.
Retourne

JSON avec predictions.

Algorithme

$$\min_{w,b}\frac{1}{2}|w|^2 + C\sum_i \max(0, 1 - y_i(w^Tx_i + b))$$

Exemple
import seraplot as sp
from sklearn.datasets import make_classification
X, y = make_classification(n_samples=500, n_features=8)
svc = sp.LinearSVC(C=1.0)
svc.fit(X, y)
print(svc.score(X, y))

LinearSvr

Regressor sklearn-compatible ⚡ SVM

LinearSVR — epsilon-insensitive linear Support Vector Regression. / LinearSVR — régression linéaire par vecteurs de support avec perte epsilon-insensible.

⚡ Rust-native ✓ sklearn parity
Quick start — Python
import seraplot as sp, numpy as np
X = np.random.randn(400, 4)
y = X[:, 0] * 2 - X[:, 2] + np.random.randn(400) * 0.5
svr = sp.LinearSVR(C=1.0, epsilon=0.1)
svr.fit(X, y)
print(svr.score(X, y))
💡
EN — Drop-in replacement: sp.LinearSvr has the same API as sklearn.
FR — Remplacement direct : même API que sklearn, changez l'import.

API Reference

JSON function name

ml_linear_svr — aliases: linear_svr

Python class
sp.LinearSvr(C=1.0, epsilon=0.1, max_iter=1000, tol=1e-4)
Constructor Parameters
ParameterTypeDefaultDescription
Cfloat1.0Regularisation parameter.
epsilonfloat0.1Epsilon-tube width.
max_iterint1000Maximum iterations.
tolfloat1e-4Convergence tolerance.
Returns

JSON with predictions.

Algorithm

$$\min_{w,b}\frac{1}{2}|w|^2 + C\sum_i \max(0, |y_i - (w^Tx_i+b)| - \varepsilon)$$

Example
import seraplot as sp, numpy as np
X = np.random.randn(400, 4)
y = X[:, 0] * 2 - X[:, 2] + np.random.randn(400) * 0.5
svr = sp.LinearSVR(C=1.0, epsilon=0.1)
svr.fit(X, y)
print(svr.score(X, y))

Référence API

Nom de fonction JSON

ml_linear_svr — alias : linear_svr

Classe Python
sp.LinearSvr(C=1.0, epsilon=0.1, max_iter=1000, tol=1e-4)
Paramètres du constructeur
ParamètreTypeDéfautDescription
Cfloat1.0Paramètre de régularisation.
epsilonfloat0.1Largeur du tube epsilon.
max_iterint1000Nombre maximum d'itérations.
tolfloat1e-4Tolérance de convergence.
Retourne

JSON avec predictions.

Algorithme

$$\min_{w,b}\frac{1}{2}|w|^2 + C\sum_i \max(0, |y_i - (w^Tx_i+b)| - \varepsilon)$$

Exemple
import seraplot as sp, numpy as np
X = np.random.randn(400, 4)
y = X[:, 0] * 2 - X[:, 2] + np.random.randn(400) * 0.5
svr = sp.LinearSVR(C=1.0, epsilon=0.1)
svr.fit(X, y)
print(svr.score(X, y))