Run models in the browser
Ship zero-backend ML experiences with full client-side inference and privacy by default.
A lightweight ML library for the browser and Node.js. Familiar fit / predict API, zero-install demos, production-ready builds.
npm install @kanaries/mlLinear.LogisticRegression.Bringing the ergonomics of scikit-learn to JavaScript and TypeScript, @kanaries/ml pairs a small, predictable estimator API with tree-shakable ESM builds — so classical machine learning runs natively in the browser, on Node.js servers, and at the edge.
The library favours practical coverage and runnable documentation over breadth for its own sake. Every estimator is typed, every algorithm has a guide, and the same fit/predict code ships from prototype to production.
Ship zero-backend ML experiences with full client-side inference and privacy by default.
Build training pipelines and production inference with Node.js and modern frameworks.
Create exploratory dashboards that react instantly without server round-trips.
Tree-shakable ESM builds, typed arrays, and Web Worker friendly execution via asyncMode.
import { Linear, utils } from '@kanaries/ml';
const X = [[5.1, 3.5], [4.9, 3.0], [7.0, 3.2]];
const y = [0, 0, 1];
// standardize features, then fit
const scaler = new utils.Preprocessing.StandardScaler();
const clf = new Linear.LogisticRegression({ maxIter: 200 });
clf.fit(scaler.fitTransform(X), y);
clf.predict([[6.1, 3.1]]); // → [1]<script type="module">
import { Clusters } from
'https://cdn.skypack.dev/@kanaries/ml';
const km = new Clusters.KMeans(2);
km.fitPredict([[1, 1], [1.2, 1.1], [5, 5]]);
// → [0, 0, 1]
</script>Client-side churn prediction, lead scoring, and data capture scoring widgets.
Intent detection, TF–IDF pipelines, and simple classifiers entirely in JS.
k-means, PCA, and dimensionality reduction for visualization dashboards.
Prototype forecasts in Node.js with classical regression and smoothing.
Just like scikit-learn: fit, predict, pipelines, transformers, and metrics.
ESM-first distribution runs anywhere JavaScript does.
Typed arrays and tight inner loops keep memory low and performance high.
Accuracy, precision/recall, F1, ROC-AUC, R², and confusion matrices ship in the metrics module.
Runnable guides for each estimator shorten onboarding time.
Import only what you need with tree-shakable modules.
| Family | Estimators & algorithms | Reference |
|---|---|---|
| Linear & SVM | Linear module · LinearRegression · LogisticRegression · SVM module · SVC / NuSVC / LinearSVC | View → |
| Tree & Ensemble | Tree module · DecisionTreeClassifier · ExtraTreeClassifier · Ensemble module · IsolationForest / AdaBoost | View → |
| Neighbors & Clustering | Neighbors module · KNearestNeighbors · BallTree / KDTree · Clusters module · KMeans · DBSCAN · OPTICS · HDBSCAN · MeanShift | View → |
| Decomposition & Manifold | Decomposition module · PCA / SparsePCA / TruncatedSVD · Manifold module · MDS / LLE / TSNE / SpectralEmbedding | View → |
| Bayes, Semi-Supervised & Utils | Bayes module · BernoulliNB / CategoricalNB · SemiSupervised module · LabelPropagation / LabelSpreading · Utils module (asyncMode, trainTestSplit, preprocessing, model selection) | View → |
Clean and transform with scalers, encoders, and pipeline helpers.
scaler.fitTransform(X)
Use the sklearn-style API to train estimators on typed arrays or plain arrays.
model.fit(X, y)
Run the same fit/predict code in browsers, Node.js, and edge functions.
model.predict(Xnew)
Yes—for small to medium datasets and interactive experiences, @kanaries/ml delivers responsive inference. Wrap heavy training or inference in utils.asyncMode to run it off the main thread and keep UIs snappy.
Absolutely. All supported algorithms can execute in modern browsers and in Node.js environments.
There is no built-in serialization yet. For now you can re-fit from stored training data, or read a fitted estimator’s parameters and reconstruct it manually.
We follow scikit-learn naming and options wherever practical. Note that some estimators take positional constructor arguments rather than keyword options, so check each algorithm page for the exact signature.
The full library is about 32 kB gzipped, and each algorithm tree-shakes to just the code you import.
Yes. utils.asyncMode runs a synchronous function in a Web Worker (browser) or worker thread (Node.js) and returns a Promise, so training and inference can stay off the main thread.
Deploy machine learning models anywhere JavaScript runs with @kanaries/ml.