@kanaries/ml
API Reference/Semi-Supervised

Label Spreading

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

Algorithm overview

LabelSpreading performs smoother semi-supervised label diffusion with regularization to reduce over-confident propagation.

This algorithm is especially useful when:

  • You want semi-supervised learning with stronger stability than pure propagation.
  • Graph neighborhoods are useful but somewhat noisy.
  • You need better robustness for low-label datasets.

JavaScript implementation

@kanaries/ml provides Label Spreading in JavaScript for semi-supervised problems where you want a smoother, regularized alternative to raw label propagation. That is useful for annotation tools and partially labeled datasets where graph-based learning should be robust to noisy neighborhoods.

Because the implementation runs in JS, teams can connect interactive labeling workflows, similarity features, and propagation-based learning without a separate Python service layer.

Quick start

LabelSpreading in Python vs JavaScript / TypeScript

If you searched for "LabelSpreading in JavaScript" or "LabelSpreading 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.semi_supervised import LabelSpreading

X = [[0, 0], [0.1, 0.2], [1, 1], [1.1, 0.9]]
y = [0, -1, 1, -1]

model = LabelSpreading(alpha=0.2)
model.fit(X, y)
pred = model.predict(X)
JavaScript / TypeScript
@kanaries/ml
import { SemiSupervised } from '@kanaries/ml';

const X = [[0, 0], [0.1, 0.2], [1, 1], [1.1, 0.9]];
const y = [0, -1, 1, -1];

const model = new SemiSupervised.LabelSpreading({ alpha: 0.2 });
model.fit(X, y);
const pred = model.predict(X);

Quick JavaScript example

import { SemiSupervised } from '@kanaries/ml';

const X = [[0, 0], [0.1, 0.2], [1, 1], [1.1, 0.9]];
const y = [0, -1, 1, -1];

const model = new SemiSupervised.LabelSpreading({ alpha: 0.2 });
model.fit(X, y);
const pred = model.predict(X);

Detailed API reference

interface LabelSpreadingOptions {
    kernel?: 'rbf' | 'knn' | ((X: number[][], Y: number[][]) => number[][]);
    gamma?: number;
    nNeighbors?: number;
    alpha?: number;
    maxIter?: number;
    tol?: number;
}
constructor(options: LabelSpreadingOptions = {})

Label spreading assigns labels to unlabeled data using a normalized graph and soft clamping controlled by alpha.

Methods

  • fit(trainX: number[][], trainY: number[]): void
  • predict(testX: number[][]): number[]
  • predictProba(testX: number[][]): number[][]

Implementation workflow

  1. Create labeled/unlabeled split and construct feature graph inputs.
  2. Fit LabelSpreading and monitor convergence behavior.
  3. Tune kernel and regularization parameters with validation labels.

JavaScript deployment notes

  • Prefer Label Spreading when graph noise or over-confident propagation is a concern.
  • Tune kernel and regularization settings against a validation subset of known labels.
  • Use it to improve label coverage before training a final supervised model rather than as the only production model.