---
title: "Support Vector Classifier (SVC) in JavaScript with @kanaries/ml"
description: "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."
canonical_url: "https://ml.kanaries.net/docs/apis/svm/SVC"
markdown_url: "https://ml.kanaries.net/docs/apis/svm/SVC.md"
---
# Support Vector Classifier (SVC) in JavaScript

## Algorithm overview

C-Support Vector Classification. `SVC` solves the SVM dual problem with an SMO solver (libsvm-style maximal-violating-pair working-set selection), the same formulation scikit-learn's `SVC` uses. It supports the full sklearn kernel set (`linear`, `rbf`, `poly`, `sigmoid`), handles multiclass problems one-vs-one, and exposes the fitted support vectors and a binary `decisionFunction` whose values line up numerically with scikit-learn's `decision_function`.

Not included yet: probability estimates (`predict_proba` / Platt scaling) are on the roadmap and not part of this release.

This algorithm is especially useful when:

- Linear models underfit complex class separation patterns.
- You can afford kernel-based training for improved boundary flexibility.
- You need strong classification performance on medium-sized datasets.

## JavaScript implementation

@kanaries/ml exposes SVC in JavaScript for teams that need non-linear decision boundaries inside browser apps or Node.js services. This is useful when a linear classifier is not expressive enough but you still want a familiar estimator API and controllable kernel settings in TypeScript.

For product teams, this means kernel-based classification can live in the same JS codebase that already handles feature construction, request handling, and user-facing logic.

## Quick start

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

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

clf = SVC(C=1.0, kernel='rbf', gamma='scale')
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.SVC({ C: 1, kernel: 'rbf', gamma: 'scale' });
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.SVC({ C: 1, kernel: 'rbf', gamma: 'scale' });
clf.fit(X, y);
const pred = clf.predict([[0.9, 0.8], [0.1, 0.2]]);
console.log(pred);
```

## Detailed API reference

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

### Parameters

- `C` (number, default `1`): regularization strength, inversely proportional to the margin softness
- `kernel` ('linear' | 'rbf' | 'poly' | 'sigmoid', default `'rbf'`): kernel type
- `gamma` (number | 'scale' | 'auto', default `'scale'`): kernel coefficient for `rbf`, `poly`, and `sigmoid`; `'scale'` = 1 / (n\_features x Var(X)), `'auto'` = 1 / n\_features
- `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

### Methods

- `fit(trainX, trainY)`: train the classifier; multiclass data is handled one-vs-one
- `predict(testX)`: predicted class labels (one-vs-one voting)
- `decisionFunction(testX)`: signed margins for binary problems; positive values mean `classes[1]`, matching sklearn's convention
- `getSupportVectors()`: sorted training-set indices of the support vectors
- `getNSupport()`: number of support vectors per class, like sklearn's `n_support_`

### Implementation workflow

1. Scale features and pick a kernel (RBF is a common starting point).
2. Fit with baseline hyperparameters and assess validation metrics.
3. Tune `C`, kernel settings, and class weights for task-specific goals.

### JavaScript deployment notes

- Use SVC when linear models underfit but the dataset is still small or medium enough for kernel methods.
- Scale features before fitting, especially with RBF kernels.
- Treat kernel choice, `C`, and `gamma` as a joint tuning problem rather than optimizing them one at a time.
