Label Spreading
Run regularized semi-supervised learning in JavaScript and TypeScript with LabelSpreading in @kanaries/ml. Includes quick start, options, and API reference.
View as MarkdownAlgorithm 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.
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)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);
console.log(pred);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[]): voidpredict(testX: number[][]): number[]predictProba(testX: number[][]): number[][]
Implementation workflow
- Create labeled/unlabeled split and construct feature graph inputs.
- Fit LabelSpreading and monitor convergence behavior.
- 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.
Label Propagation
Propagate labels across partially labeled datasets in JavaScript and TypeScript with LabelPropagation in @kanaries/ml for browser and Node.js workflows.
Self-Training Classifier
Run semi-supervised pseudo-labeling in JavaScript and TypeScript with SemiSupervised.SelfTrainingClassifier from @kanaries/ml for browser and Node.js.