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.
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]])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, default0.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 balancekernel('linear' | 'rbf' | 'poly' | 'sigmoid', default'rbf'): kernel typegamma(number | 'scale' | 'auto', default'scale'): kernel coefficient forrbf,poly, andsigmoiddegree(number, default3): degree of the polynomial kernelcoef0(number, default0): independent term of thepolyandsigmoidkernelstol(number, default1e-3): KKT-violation tolerance for SMO convergencemaxIter(number, default-1): hard limit on SMO pair updates;-1runs 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
- Choose kernel and initialize a conservative
nuvalue. - Fit NuSVC and inspect validation accuracy and support vector count.
- 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.
Support Vector Classifier (SVC)
Learn what Support Vector Classifier (SVC) does, when to use it, and how to run SVC in JavaScript or TypeScript with @kanaries/ml for browser and Node.js applications.
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.