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.
Paste CSV data and compute results locally with zero server uploads and exportable JS/Python code.
Outlier Calculator · Confusion Matrix & F1 · Logistic Regression · Polynomial Regression · Customer Segmentation
Drag points, tune hyperparameters, and watch live decision surfaces and optimization paths update.
PCA Biplot · KNN Boundaries · K-Means Steps · Gradient Descent · Decision Tree · Random Forest
Task-first guides, runtime comparisons, and side-by-side Python scikit-learn translations for production JS/TS teams.
scikit-learn Equivalents · JS ML Libraries Comparison · Migrate sklearn Pipeline to TS · Edge & Web Workers ML · Isolation Forest Guide · IQR vs Z-Score vs IForest
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.
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.
Yes. Fitted estimators support a versioned JSON serialization envelope via model.toJSON() (or JSON.stringify(model)) and can be restored anywhere with the root loadModel() helper.
We mirror scikit-learn naming, fit/predict/transform contracts, Pipelines, and options-object constructors wherever practical, while preserving legacy positional overloads for backwards compatibility. See the scikit-learn equivalents table for exact mappings.
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.