Skip to Content
OchreML
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 so C and epsilon behave consistently across features.

Hardware Backend Support

BackendPrimitives UsedSupport
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.

ParameterTypeDefaultDescription
epsilonfloat0.0Width of the epsilon-insensitive tube where prediction errors incur zero penalty.
tolfloat1e-4Tolerance for stopping criteria.
Cfloat1.0Inverse 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_interceptboolTrueWhether to fit an intercept term.
intercept_scalingfloat1.0Synthetic feature value appended when fit_intercept=True.
dual"auto" | bool"auto"Whether to solve the dual or primal optimization problem.
random_stateint | NoneNoneSeed controlling coordinate shuffling in dual coordinate descent.
max_iterint1000Maximum number of solver iterations.
devicestr | NoneNoneTarget compute device ("auto", "cpu", "cuda:0", "wgpu", "tpu:0"). Defaults to ochreml.get_default_device().

Attributes

AttributeTypeDescription
coef_ndarray of shape (n_features,)Weights assigned to the features.
intercept_ndarray of shape (1,)Intercept (bias) term.
n_features_in_intNumber of features seen during fit.
n_iter_intNumber of iterations executed by the solver.

Methods

MethodSignatureDescription
fitfit(X, y, sample_weight=None) -> selfFit linear SVR model on (X, y).
predictpredict(X) -> ndarrayPredict continuous target values for samples in X.
scorescore(X, y) -> floatReturn coefficient of determination R^2.
toto(device: str) -> selfMove the estimator execution target to another hardware device.
save / loadreg.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]))

On this page