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

LinearRegression

Regressor sklearn-compatible 📈 Linear

Ordinary Least Squares linear regression — analytical Gram/Cholesky solver. / Régression linéaire par moindres carrés ordinaires — solveur analytique Gram/Cholesky.

⚡ Rust-native ✓ sklearn parity
Quick start — Python
import seraplot as sp, numpy as np
X = np.random.randn(500, 4)
y = X @ [2, -1, 0.5, 1.5] + np.random.randn(500) * 0.3
model = sp.LinearRegression()
model.fit(X, y)
print(model.coef_, model.intercept_, model.score(X, y))
💡
EN — Drop-in replacement: sp.LinearRegression has the same API as sklearn.
FR — Remplacement direct : même API que sklearn, changez l'import.

API Reference

JSON function name

ml_linear_regression — aliases: linear_regression, linreg

Python class
sp.LinearRegression(fit_intercept=true)
Constructor Parameters
ParameterTypeDefaultDescription
fit_interceptbooltrueFit an intercept term.
Returns

JSON with predictions, coef, intercept.

Algorithm

$$\hat{\beta} = (X^T X)^{-1} X^T y$$

Example
import seraplot as sp, numpy as np
X = np.random.randn(500, 4)
y = X @ [2, -1, 0.5, 1.5] + np.random.randn(500) * 0.3
model = sp.LinearRegression()
model.fit(X, y)
print(model.coef_, model.intercept_, model.score(X, y))

Référence API

Nom de fonction JSON

ml_linear_regression — alias : linear_regression, linreg

Classe Python
sp.LinearRegression(fit_intercept=true)
Paramètres du constructeur
ParamètreTypeDéfautDescription
fit_interceptbooltrueAjuster un terme d'intercept.
Retourne

JSON avec predictions, coef, intercept.

Algorithme

$$\hat{\beta} = (X^T X)^{-1} X^T y$$

Exemple
import seraplot as sp, numpy as np
X = np.random.randn(500, 4)
y = X @ [2, -1, 0.5, 1.5] + np.random.randn(500) * 0.3
model = sp.LinearRegression()
model.fit(X, y)
print(model.coef_, model.intercept_, model.score(X, y))