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

Ridge

Regressor sklearn-compatible 📈 Linear

Ridge regression — L2-penalised OLS with Cholesky solver. / Régression Ridge — OLS pénalisée L2 avec solveur Cholesky.

⚡ Rust-native ✓ sklearn parity
Quick start — Python
import seraplot as sp, numpy as np
X = np.random.randn(300, 5)
y = X @ np.array([1, -2, 0.5, 1.5, -0.8]) + np.random.randn(300)
reg = sp.Ridge(alpha=0.5)
reg.fit(X, y)
print(f"R²: {reg.score(X, y):.4f}")
💡
EN — Drop-in replacement: sp.Ridge has the same API as sklearn.
FR — Remplacement direct : même API que sklearn, changez l'import.

API Reference

JSON function name

ml_ridge — aliases: ridge, ridge_regression

Python class
sp.Ridge(alpha=1.0, fit_intercept=true)
Constructor Parameters
ParameterTypeDefaultDescription
alphafloat1.0L2 regularisation strength.
fit_interceptbooltrueFit an intercept term.
Returns

JSON with predictions, coef, intercept.

Algorithm

$$\hat{\beta} = (X^TX + \alpha I)^{-1}X^Ty$$

Example
import seraplot as sp, numpy as np
X = np.random.randn(300, 5)
y = X @ np.array([1, -2, 0.5, 1.5, -0.8]) + np.random.randn(300)
reg = sp.Ridge(alpha=0.5)
reg.fit(X, y)
print(f"R²: {reg.score(X, y):.4f}")

Référence API

Nom de fonction JSON

ml_ridge — alias : ridge, ridge_regression

Classe Python
sp.Ridge(alpha=1.0, fit_intercept=true)
Paramètres du constructeur
ParamètreTypeDéfautDescription
alphafloat1.0Force de régularisation L2.
fit_interceptbooltrueAjuster un terme d'intercept.
Retourne

JSON avec predictions, coef, intercept.

Algorithme

$$\hat{\beta} = (X^TX + \alpha I)^{-1}X^Ty$$

Exemple
import seraplot as sp, numpy as np
X = np.random.randn(300, 5)
y = X @ [1, -2, 0.5, 1.5, -0.8] + np.random.randn(300)
reg = sp.Ridge(alpha=0.5)
reg.fit(X, y)
print(f"R² : {reg.score(X, y):.4f}")

RidgeClassifier

Classifier sklearn-compatible 📈 Linear

Ridge classifier — one-vs-rest Ridge regression mapped to class labels. / Classificateur Ridge — régression Ridge one-vs-rest mappée en labels.

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

API Reference

JSON function name

ml_ridge_classifier — aliases: ridge_classifier, ridge_cls

Python class
sp.RidgeClassifier(alpha=1.0)
Constructor Parameters
ParameterTypeDefaultDescription
alphafloat1.0L2 regularisation strength.
Returns

JSON with predictions.

Algorithm

$$\hat{y} = \text{sign}(X\hat{\beta}), \quad \hat{\beta} = (X^TX + \alpha I)^{-1}X^TY$$

Example
import seraplot as sp, numpy as np
X = np.random.randn(300, 5)
y = (X[:, 0] - X[:, 2] > 0).astype(int)
clf = sp.RidgeClassifier(alpha=1.0)
clf.fit(X, y)
print(f"Accuracy: {clf.score(X, y):.3f}")

Référence API

Nom de fonction JSON

ml_ridge_classifier — alias : ridge_classifier, ridge_cls

Classe Python
sp.RidgeClassifier(alpha=1.0)
Paramètres du constructeur
ParamètreTypeDéfautDescription
alphafloat1.0Force de régularisation L2.
Retourne

JSON avec predictions.

Algorithme

$$\hat{y} = \text{sign}(X\hat{\beta}), \quad \hat{\beta} = (X^TX + \alpha I)^{-1}X^TY$$

Exemple
import seraplot as sp, numpy as np
X = np.random.randn(300, 5)
y = (X[:, 0] - X[:, 2] > 0).astype(int)
clf = sp.RidgeClassifier(alpha=1.0)
clf.fit(X, y)
print(f"Précision : {clf.score(X, y):.3f}")