Skip to Content
OchreML
Kernel, MLP & Gaussian Process

SVR

Epsilon-Support Vector Regression using 2N LIBSVM-style dual SMO and hardware-accelerated kernel Gram matrices.

Overview

SVR implements epsilon-insensitive Support Vector Regression using a 2N LIBSVM-style dual Sequential Minimal Optimization (SMO) solver in Rust. Predictions within an epsilon-tube around the target incur no loss, while points outside the tube become support vectors weighted by C. (^▽^)

Backend Support

  • Primitives: N3 (pairwise L2 distance for RBF kernels), E1 (dense matrix multiplication for linear, polynomial, and sigmoid Gram matrices)
  • Devices: cpu (Rayon parallel f64), cuda / cuda:0 (dynamic cuBLAS), wgpu (Vulkan/Metal/DX12), tpu (OpenXLA PJRT), and auto
  • Persistence: .dit binary format via save() / load() (and ochreml.save() / ochreml.load()), plus Python pickle support

Import & Signature

from ochreml.svm import SVR
# Also available from top-level: from ochreml import SVR

SVR(
    kernel: str = "rbf",
    degree: int = 3,
    gamma: str | float = "scale",
    coef0: float = 0.0,
    tol: float = 1e-3,
    C: float = 1.0,
    epsilon: float = 0.1,
    max_iter: int = -1,
    device: str | None = None,
)

Parameters

ParameterTypeDefaultDescription
kernel{"linear", "poly", "rbf", "sigmoid", "precomputed"}"rbf"Kernel function used to compute the Gram matrix.
degreeint3Degree of the polynomial kernel (kernel="poly"). Ignored by other kernels.
gamma{"scale", "auto"} or float"scale"Kernel coefficient for "rbf", "poly", and "sigmoid". "scale" uses 1 / (n_features * X.var()); "auto" uses 1 / n_features.
coef0float0.0Independent term in "poly" and "sigmoid" kernel functions.
tolfloat1e-3Tolerance for the SMO stopping criterion.
Cfloat1.0Regularization parameter. Must be strictly positive (C > 0).
epsilonfloat0.1Width of the epsilon-tube within which no penalty is associated in the training loss function.
max_iterint-1Hard limit on solver iterations, or -1 for no limit.
devicestr | NoneNoneTarget compute device ("auto", "cpu", "cuda:0", "wgpu", "tpu:0"). Defaults to ochreml.get_default_device().

Attributes

AttributeTypeDescription
support_ndarray of shape (n_SV,)Indices of support vectors in the training set.
support_vectors_ndarray of shape (n_SV, n_features)Support vectors extracted during fitting.
dual_coef_ndarray of shape (1, n_SV)Dual coefficients of the support vectors in the regression function.
intercept_ndarray of shape (1,)Constant intercept term in the decision function.
n_features_in_intNumber of features seen during fit().
device_str | NoneResolved execution device string.

Methods

MethodSignatureDescription
fitfit(X, y) -> SVRFit the SVR model on feature matrix X and continuous target vector y.
predictpredict(X) -> ndarrayPredict continuous target values for samples in X.
scorescore(X, y) -> floatReturn the coefficient of determination (R^2) on (X, y).
toto(device) -> SVRMove the estimator's compute target to another device.
savesave(path) -> NoneSave the fitted model to a .dit binary file.
loadSVR.load(path, device=None) -> SVRClass method to load a fitted model from a .dit file.

Example

import numpy as np
from ochreml.svm import SVR

rng = np.random.default_rng(42)
X = np.linspace(-3.0, 3.0, 60).reshape(-1, 1)
y = np.sin(X[:, 0]) + 0.05 * rng.normal(size=60)

reg = SVR(kernel="rbf", C=10.0, epsilon=0.05, gamma="scale")
reg.fit(X, y)

X_query = np.array([[-1.5], [0.0], [1.5]])
print("Predictions:", reg.predict(X_query))
print("R^2 score:", reg.score(X, y))
print("Number of support vectors:", len(reg.support_))

On this page