Machine Learning in JavaScript — scikit-learn style

A lightweight JS machine learning library for browser and Node.js. Familiar scikit-learn API, zero-install demos, production-ready builds.

Why JavaScript for ML?

Run models in the browser

Ship zero-backend ML experiences with full client-side inference and privacy by default.

One language front to back

Build training pipelines and production inference with Node.js and modern frameworks.

Interactive ML UIs

Create exploratory dashboards that react instantly without server round-trips.

Tiny bundles & WASM-ready

Tree-shakable ESM builds, typed arrays and Web Worker friendly execution.

What you can build

Tabular

Client-side churn prediction, lead scoring, and data capture scoring widgets.

Text

Intent detection, TF–IDF pipelines, and simple classifiers entirely in JS.

Clustering & DR

k-means, PCA, and dimensionality reduction for visualization dashboards.

Time series

Prototype forecasts in Node.js with classical regression and smoothing.

Key features

Familiar API

Just like scikit-learn: fit, predict, pipelines, transformers, and metrics.

Browser & Node support

ESM-first distribution runs anywhere JavaScript does.

Fast numerics

Typed arrays and WASM-friendly architecture keep memory low and performance high.

Model persistence

Serialize trained pipelines to JSON and reload them in any runtime.

Docs for every algorithm

Runnable guides for each estimator shorten onboarding time.

Tiny footprint

Import only what you need with tree-shakable modules.

Quick start

Install

yarn add @kanaries/ml

Node.js

import { StandardScaler, LogisticRegression } from '@kanaries/ml';

const X = [
  [5.1, 3.5],
  [4.9, 3.0],
  [7.0, 3.2],
];
const y = [0, 0, 1];

const scaler = new StandardScaler();
const Xs = scaler.fitTransform(X);
const clf = new LogisticRegression({ maxIter: 200 }).fit(Xs, y);

console.log(clf.predict([[6.1, 3.1]]));
Use from a CDN (browser)
<script type="module">
  import { KMeans } from 'https://cdn.skypack.dev/@kanaries/ml';

  const km = new KMeans({ k: 3 }).fit([
    [1, 1],
    [1.2, 1.1],
    [5, 5],
  ]);

  console.log(km.predict([[1.1, 1]]));
</script>

Supported algorithms

Benchmarks & footprint

Core bundle < 50 kB gzipped; individual algorithms typically stay below 15 kB. Use Web Workers for CPU-heavy tasks and opt into the WASM build for additional throughput.

Explore performance charts for training time vs. samples and inference vs. feature counts in the dedicated benchmarks section.

See all benchmarks →

How it works

1

Prepare data

Clean and transform with scalers, encoders, and pipeline helpers.

2

Fit a model

Use the sklearn-style API to train estimators on typed arrays or plain arrays.

3

Deploy anywhere

Persist to JSON, load in browsers or Node.js, and call predict in milliseconds.

Compare with scikit-learn

Understand parameter parity, migration tips, and when it makes sense to stay in Python versus delivering ML experiences directly in the browser.

Migration guide →

FAQ

Is JavaScript fast enough for ML?

Yes—for small to medium datasets and interactive experiences, @kanaries/ml delivers responsive inference. Use Web Workers to keep UIs snappy and review our benchmarks for throughput guidance.

Does it run fully in the browser?

Absolutely. All supported algorithms can execute in modern browsers and in Node.js environments.

Can I save and load models?

Every estimator can serialize parameters to JSON. Reload them in any JS runtime and resume predictions instantly.

How close is the API to scikit-learn?

We follow scikit-learn naming and options wherever practical. The migration guide highlights the rare differences.

How big is the bundle?

The core stays well below typical UI bundle budgets and each algorithm tree-shakes to just the code you import. See the benchmarks section for the latest size numbers.

Does it support Web Workers or WASM?

Yes. The runtime is designed for off-main-thread execution and plays nicely with WASM-backed kernels.

Join the community

Build ML in JavaScript today

Deploy machine learning models anywhere JavaScript runs with @kanaries/ml.