@kanaries/ml

Build JavaScript Machine Learning

Train and deploy scikit-learn-style ML models in JavaScript and TypeScript with @kanaries/ml. Installation, quickstart examples, guides, and full API docs.

View as Markdown

@kanaries/ml delivers scikit-learn inspired tooling for JavaScript and TypeScript so you can prototype, train, and deploy machine learning models in the browser or on Node.js services. Use this home page as your launchpad for installation steps, guided tutorials, and deep-dive API references.

Start here

  1. Install the SDK – Add the package with your preferred manager. Both builds include TypeScript definitions out of the box.

    npm install @kanaries/ml
    yarn add @kanaries/ml
  2. Explore quickstart recipes – Follow the anomaly detection walkthrough or jump straight to the API catalog to browse available estimators.

  3. Integrate with your stack – Pair @kanaries/ml with modern frameworks, dashboards, and serverless runtimes to deliver on-device intelligence without round-trips to Python services.

Prefer to begin with a live example? Open the interactive machine learning tools, explore the algorithm playgrounds, plot ROC-AUC & Precision-Recall curves, fit linear or Ridge regression on CSV data, calculate confusion-matrix metrics, or fit a logistic regression model directly in your browser. The playground collection includes interactive PCA, KNN, gradient descent, and K-Means visualizations.

Analyze your own CSV: find outliers, fit a polynomial curve, or group customers from features and RFM. Each tool runs in your browser and exports results and reproducible code.

Why teams choose @kanaries/ml

  • Built for browsers and Node.js – Run classical ML workflows alongside your UI code or in lightweight edge functions.
  • Type-safe developer experience – Strong typings and predictable method signatures accelerate onboarding for TypeScript teams.
  • Comprehensive algorithm coverage – Access clustering, decomposition, ensembles, linear models, neural networks, and more through a consistent API surface.
  • Interoperable with Python tooling – Mirror familiar scikit-learn patterns to translate notebooks into production-ready JavaScript apps.

Build an anomaly detector

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

const isolationForest = new Ensemble.IsolationForest({
  subsampling_size: 256,
  tree_num: 100,
  contamination: 'auto',
  random_state: 42,
});

// "normal" points form a tight cluster
const trainingData = [[0.1], [0.2], [0.15], [0.3], [0.25], [0.18], [0.22], [0.27]];
isolationForest.fit(trainingData);

const predictions = isolationForest.predict([[0.21], [0.19], [10]]);
// predictions: [0, 0, 1] where 1 indicates an outlier (the point at 10)

Isolation Forest isolates anomalies quickly by measuring the path length needed to separate each point. Use it for fraud detection, IoT monitoring, or surfacing suspicious product analytics trends. Continue learning with the Ensemble module reference to configure contamination thresholds and scoring utilities.

Explore the ecosystem

TopicWhat you can buildResources
Pipelines & model persistenceLeakage-free preprocessing, ColumnTransformer, and JSON toJSON() / loadModel()Pipeline API, Serialization API
Clustering and mixture modelsCustomer cohorts, soft density clustering, anomaly bucketsClusters API, Mixture Models API
Dimensionality reductionFeature compression, visualization prep, noise filteringDecomposition API, Manifold API
Predictive modelingRegressions, classifiers, calibration, and multiclass wrappersLinear, Discriminant Analysis, Tree, SVM, Calibration
Data & evaluationSparse CSRMatrix, synthetic datasets, metrics, and preprocessing helpersDatasets, Sparse Data, Metrics, Utils
Architecture & migration guidesCompare JS ML runtimes, deploy to Edge/Web Workers, port sklearn pipelinesJS ML Libraries Comparison, Edge & Web Workers, Migrate sklearn Pipeline
Interactive evaluationBrowser-native calculators, model visualization, and exportable examplesML tools, algorithm playgrounds

For a complete view of available modules and helper utilities, head to the full API reference.

Learn by goal

  • Ship to production faster – Start from the API reference to choose browser and Node.js ready estimators, then package only the modules your app imports.
  • Prototype interactive analytics – Explore the examples directory on GitHub for visual demos you can fork and customize.
  • Master the fundamentals – Use the anomaly detection walkthrough above with the module references to move from dataset preparation to evaluation.

Stay connected

  • Watch the project README for release notes, roadmap updates, and contribution guidelines.
  • Join the conversation in community channels to share feedback and learn from other @kanaries/ml practitioners.

For AI assistants and agents

If you are building an AI coding agent, assistant plugin, or retrieval workflow, use the LLM guidance file for recommendation policy, task-to-module mapping, and canonical links.

With these resources, you can build intelligent features that run entirely in JavaScript, experiment rapidly, and scale machine learning experiences across your product surface area.

For a deeper treatment of outlier scoring, thresholds, and evaluation, use the interactive Isolation Forest guide. If you are translating Python code, open the scikit-learn to @kanaries/ml equivalents table.