---
title: "Linear SVC in JavaScript with @kanaries/ml"
description: "Learn what Linear SVC does, when to use it, and how to run LinearSVC in JavaScript or TypeScript with @kanaries/ml for browser and Node.js applications."
canonical_url: "https://ml.kanaries.net/docs/apis/svm/LinearSVC"
markdown_url: "https://ml.kanaries.net/docs/apis/svm/LinearSVC.md"
---
# Linear SVC in JavaScript

## Algorithm overview

Linear support vector classifier trained with the Pegasos algorithm (primal stochastic subgradient descent on hinge loss). It trains one-versus-rest linear models to separate classes.

LinearSVC trains linear support vector classifiers optimized for high-dimensional and sparse feature spaces.

This algorithm is especially useful when:

- You have many features (for example text vectors) and need fast linear classification.
- Margin-based classification outperforms logistic baselines in your tests.
- You need robust performance with controlled model complexity.

## JavaScript implementation

@kanaries/ml includes Linear SVC in JavaScript for classification tasks that need margin-based decision boundaries but still want the simplicity of a linear model. This is useful for TypeScript services and browser tools working with high-dimensional but still relatively lightweight feature vectors.

Because it stays in the JS runtime, teams can integrate feature extraction, decision logic, and linear classification into the same application layer without additional serving infrastructure.

## Quick start

### LinearSVC: 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 LinearSVC

X = [[0, 0], [1, 1], [1, 0], [0, 1]]
y = [0, 1, 1, 0]

clf = LinearSVC(C=1.0, max_iter=2000, random_state=0)
clf.fit(X, y)
pred = clf.predict([[0.9, 0.8], [0.1, 0.2]])
```

#### JavaScript / TypeScript (@kanaries/ml)

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

const X = [[0, 0], [1, 1], [1, 0], [0, 1]];
const y = [0, 1, 1, 0];

const clf = new SVM.LinearSVC({ C: 1, maxIter: 1000, randomState: 0 });
clf.fit(X, y);
const pred = clf.predict([[0.9, 0.8], [0.1, 0.2]]);
```

### Quick JavaScript example

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

const X = [[0, 0], [1, 1], [1, 0], [0, 1]];
const y = [0, 1, 1, 0];

const clf = new SVM.LinearSVC({ C: 1, maxIter: 1000, randomState: 0 });
clf.fit(X, y);
const pred = clf.predict([[0.9, 0.8], [0.1, 0.2]]);
console.log(pred);
```

## Detailed API reference

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

### Parameters

- `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. Scale/normalize features and choose regularization strength.
2. Fit the classifier and evaluate margin-driven classification metrics.
3. Tune `C` and class weighting to match recall/precision priorities.

### JavaScript deployment notes

- Linear SVC is a good fit for high-dimensional feature spaces where a linear boundary is sufficient.
- Scale features before training so the margin optimization behaves more predictably.
- Compare against logistic regression when you need to trade off margin behavior versus probability-oriented interpretation.
