@kanaries/ml
API Reference/SVM

Linear SVR

Learn what Linear SVR does, when to use it, and how to run LinearSVR in JavaScript or TypeScript with @kanaries/ml for browser and Node.js applications.

Algorithm overview

Linear support vector regression trained with Pegasos-style stochastic subgradient descent on the epsilon-insensitive loss.

LinearSVR performs margin-based linear regression with robustness to moderate outliers in target values.

This algorithm is especially useful when:

  • You need regression in high-dimensional spaces with linear assumptions.
  • Outlier sensitivity from ordinary least squares is causing instability.
  • You want a fast margin-based baseline in Node.js services.

JavaScript implementation

@kanaries/ml provides Linear SVR in JavaScript for regression tasks where a linear support-vector objective is preferable to plain least squares. This can be useful in Node.js services and TypeScript applications that need linear-style regression with a margin-based loss and straightforward inference.

It is especially attractive when the rest of the product pipeline is already in JS and you want to keep feature generation and prediction together.

Quick start

LinearSVR in Python vs JavaScript / TypeScript

If you searched for "LinearSVR in JavaScript" or "LinearSVR in TypeScript", this section maps the familiar scikit-learn call to the equivalent @kanaries/ml usage for browser and Node.js runtimes.

Python
scikit-learn
from sklearn.svm import LinearSVR

X = [[0], [1], [2], [3]]
y = [1.0, 2.1, 2.9, 4.2]

reg = LinearSVR(C=1.0, epsilon=0.0, random_state=0)
reg.fit(X, y)
pred = reg.predict([[1.5], [2.5]])
JavaScript / TypeScript
@kanaries/ml
import { SVM } from '@kanaries/ml';

const X = [[0], [1], [2], [3]];
const y = [1.0, 2.1, 2.9, 4.2];

const reg = new SVM.LinearSVR({ C: 1, epsilon: 0, maxIter: 1000, randomState: 0 });
reg.fit(X, y);
const pred = reg.predict([[1.5], [2.5]]);

Quick JavaScript example

import { SVM } from '@kanaries/ml';

const X = [[0], [1], [2], [3]];
const y = [1.0, 2.1, 2.9, 4.2];

const reg = new SVM.LinearSVR({ C: 1, epsilon: 0, maxIter: 1000, randomState: 0 });
reg.fit(X, y);
const pred = reg.predict([[1.5], [2.5]]);

Detailed API reference

interface LinearSVRProps {
    epsilon?: number;
    C?: number;
    maxIter?: number;
    /** @deprecated ignored — Pegasos uses the schedule eta_t = 1/(lambda*t) */
    learningRate?: number;
    tol?: number;
    randomState?: number;
}
constructor(props: LinearSVRProps = {})

Parameters

  • epsilon (number, default 0): width of the insensitive tube around the regression line
  • C (number, default 1): regularization strength, matching sklearn's C semantics (internally lambda = 1/(n*C))
  • maxIter (number, default 1000): maximum number of training epochs (full passes over the data)
  • tol (number, default 1e-4): stopping tolerance — training stops early when the relative improvement of the objective between epochs falls below this value
  • randomState (number, optional): seed for the per-epoch shuffling, for reproducible training
  • learningRate (deprecated, ignored): the Pegasos optimizer uses the fixed step-size schedule eta_t = 1/(lambda*t), so this option has no effect

Implementation workflow

  1. Prepare standardized numeric features and choose epsilon margin.
  2. Fit LinearSVR and measure MAE/RMSE on holdout data.
  3. Tune C and epsilon for error tolerance versus fit quality.

JavaScript deployment notes

  • Use Linear SVR when you want a linear regressor with support-vector-style robustness around small errors.
  • Standardize features before training because optimization is sensitive to scale.
  • Benchmark it against ordinary linear regression to confirm the margin-based objective improves real error metrics.