---
title: "Linear SVR in JavaScript with @kanaries/ml"
description: "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."
canonical_url: "https://ml.kanaries.net/docs/apis/svm/LinearSVR"
markdown_url: "https://ml.kanaries.net/docs/apis/svm/LinearSVR.md"
---
# Linear SVR in JavaScript

## 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.

## Interactive Linear SVR playground

Tune `C`, change the data noise, and add observations to test the epsilon-insensitive fit. The prediction line is trained live with `SVM.LinearSVR` in your browser.

> The HTML version includes an interactive Linear SVR playground powered by @kanaries/ml. You can change the dataset, noise, and model controls; add observations; and inspect live predictions plus train and holdout metrics. The runnable guide and API reference continue below. [Open the HTML page](https://ml.kanaries.net/docs/apis/svm/LinearSVR).

## Quick start

### LinearSVR: Python and JavaScript / TypeScript

The Python example uses scikit-learn; the TypeScript example uses @kanaries/ml in browser or Node.js runtimes.

#### Python (scikit-learn)

```python
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)

```ts
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

```ts
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]]);
console.log(pred);
```

## Detailed API reference

```ts
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.
