@kanaries/ml
API Reference/SVM

Linear SVC

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.

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 in Python vs JavaScript / TypeScript

If you searched for "LinearSVC in JavaScript" or "LinearSVC 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 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
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

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]]);

Detailed API reference

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.