Linear, GLM & Linear SVM
LinearSVR
Linear Support Vector Regression with epsilon-insensitive or squared epsilon-insensitive loss via dual coordinate descent and primal L-BFGS.
Overview
LinearSVR implements linear Support Vector Regression by minimizing an L2-regularized epsilon-insensitive tube loss ("epsilon_insensitive" or "squared_epsilon_insensitive"). Errors within |y - y_hat| <= epsilon incur zero loss, providing robustness to small noise while scaling linearly to large datasets.
When dual="auto", OchreML selects dual=True for loss="epsilon_insensitive" and dual=(n_samples < n_features) for loss="squared_epsilon_insensitive".
When to Use
- Large-scale linear regression where an epsilon-insensitive tolerance band around predictions is desirable.
- Outlier-tolerant regression with
loss="epsilon_insensitive", where large residuals grow linearly rather than quadratically. - Standardize features (for example with
StandardScaler) before fitting soCandepsilonbehave consistently across features.
Hardware Backend Support
| Backend | Primitives Used | Support |
|---|---|---|
| CPU (Rayon) | Dense E1-E5, N2 (f64) | Full (default fallback) |
CUDA (cuda:0, cuda:all) | cuBLAS FP64 matvec & primal gradients (E1-E5, N2) | Full |
wgpu (wgpu) | WGSL compute shaders (E1-E5, N2) | Full |
TPU (tpu:0) | OpenXLA PJRT (E1-E5, N2) | Full |
Import & Constructor
from ochreml.svm import LinearSVR
# or top-level lazy import:
from ochreml import LinearSVR
reg = LinearSVR(
*,
epsilon: float = 0.0,
tol: float = 1e-4,
C: float = 1.0,
loss: str = "epsilon_insensitive",
fit_intercept: bool = True,
intercept_scaling: float = 1.0,
dual: str | bool = "auto",
random_state: int | None = None,
max_iter: int = 1000,
device: str | None = None,
)Parameters
All constructor parameters are keyword-only.
| Parameter | Type | Default | Description |
|---|---|---|---|
epsilon | float | 0.0 | Width of the epsilon-insensitive tube where prediction errors incur zero penalty. |
tol | float | 1e-4 | Tolerance for stopping criteria. |
C | float | 1.0 | Inverse regularization strength; must be strictly positive. |
loss | "epsilon_insensitive" | "squared_epsilon_insensitive" | "epsilon_insensitive" | Loss function ("epsilon_insensitive" is L1 tube loss; "squared_epsilon_insensitive" is L2 tube loss). |
fit_intercept | bool | True | Whether to fit an intercept term. |
intercept_scaling | float | 1.0 | Synthetic feature value appended when fit_intercept=True. |
dual | "auto" | bool | "auto" | Whether to solve the dual or primal optimization problem. |
random_state | int | None | None | Seed controlling coordinate shuffling in dual coordinate descent. |
max_iter | int | 1000 | Maximum number of solver iterations. |
device | str | None | None | Target compute device ("auto", "cpu", "cuda:0", "wgpu", "tpu:0"). Defaults to ochreml.get_default_device(). |
Attributes
| Attribute | Type | Description |
|---|---|---|
coef_ | ndarray of shape (n_features,) | Weights assigned to the features. |
intercept_ | ndarray of shape (1,) | Intercept (bias) term. |
n_features_in_ | int | Number of features seen during fit. |
n_iter_ | int | Number of iterations executed by the solver. |
Methods
| Method | Signature | Description |
|---|---|---|
fit | fit(X, y, sample_weight=None) -> self | Fit linear SVR model on (X, y). |
predict | predict(X) -> ndarray | Predict continuous target values for samples in X. |
score | score(X, y) -> float | Return coefficient of determination R^2. |
to | to(device: str) -> self | Move the estimator execution target to another hardware device. |
save / load | reg.save(path) / LinearSVR.load(path, device=None) | Persist or restore the model in OchreML's binary .dit format. |
Usage Example
import numpy as np
import ochreml
from ochreml.svm import LinearSVR
rng = np.random.default_rng(42)
X = rng.standard_normal((300, 4))
y = X @ np.array([2.5, -1.0, 0.5, 1.8]) + 0.4 + rng.normal(0.0, 0.15, size=300)
reg = LinearSVR(
epsilon=0.1,
C=1.0,
loss="epsilon_insensitive",
dual="auto",
random_state=42,
device="auto",
)
reg.fit(X, y)
preds = reg.predict(X[:5])
print(f"R^2: {reg.score(X, y):.4f}, coef_: {reg.coef_.round(3)}")
# Persist to .dit and reload
reg.save("linear_svr.dit")
loaded = ochreml.load("linear_svr.dit", device="cpu")
assert np.allclose(preds, loaded.predict(X[:5]))