@kanaries/ml
API Reference/SVM

NuSVC

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

Algorithm overview

ν-Support Vector Classification. NuSVC solves the ν-SVM dual problem with an SMO solver (libsvm Solver_NU semantics), like scikit-learn's NuSVC. Instead of the cost parameter C, it takes nu ∈ (0, 1]: an upper bound on the fraction of margin errors and a lower bound on the fraction of support vectors. Raising nu therefore reliably increases the number of support vectors.

Feasibility constraint: nu must satisfy nu <= 2 * min(n+, n-) / n for every pair of classes (checked per one-vs-one subproblem); otherwise fit throws specified nu is infeasible, the same error scikit-learn raises.

JavaScript implementation

@kanaries/ml makes NuSVC available in JavaScript for teams that want SVM-style classification with nu controlling model behavior instead of tuning only through C. This is useful in experimentation-heavy JS workflows where hyperparameter semantics need to match an existing Python or scikit-learn mental model.

Keeping NuSVC in the same TypeScript runtime also makes it easier to compare linear and kernel SVM variants inside one application stack.

Quick start

NuSVC in Python vs JavaScript / TypeScript

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

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

clf = NuSVC(nu=0.4, kernel='rbf', gamma='scale')
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.NuSVC({ nu: 0.4, kernel: 'rbf', gamma: 'scale' });
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.NuSVC({ nu: 0.4, kernel: 'rbf', gamma: 'scale' });
clf.fit(X, y);
const pred = clf.predict([[0.9, 0.8], [0.1, 0.2]]);

Detailed API reference

interface NuSVCProps {
    nu?: number;
    kernel?: 'linear' | 'rbf' | 'poly' | 'sigmoid';
    gamma?: number | 'scale' | 'auto';
    degree?: number;
    coef0?: number;
    tol?: number;
    maxIter?: number;
}
constructor(props: NuSVCProps = {})

Parameters

  • nu (number, default 0.5): upper bound on the fraction of margin errors, lower bound on the fraction of support vectors; must be in (0, 1] and feasible for the class balance
  • kernel ('linear' | 'rbf' | 'poly' | 'sigmoid', default 'rbf'): kernel type
  • gamma (number | 'scale' | 'auto', default 'scale'): kernel coefficient for rbf, poly, and sigmoid
  • degree (number, default 3): degree of the polynomial kernel
  • coef0 (number, default 0): independent term of the poly and sigmoid kernels
  • tol (number, default 1e-3): KKT-violation tolerance for SMO convergence
  • maxIter (number, default -1): hard limit on SMO pair updates; -1 runs until convergence

There is no C parameter: nu replaces it, exactly as in scikit-learn. NuSVC otherwise shares SVC's API, including decisionFunction, getSupportVectors, and getNSupport.

Implementation workflow

  1. Choose kernel and initialize a conservative nu value.
  2. Fit NuSVC and inspect validation accuracy and support vector count.
  3. Tune kernel and nu jointly for generalization and runtime limits.

JavaScript deployment notes

  • Use NuSVC when you prefer nu-based control over support vectors and margin behavior.
  • Scale features before training, especially for kernel-based setups.
  • Compare it directly with SVC in validation because the best control scheme depends on the dataset.