@kanaries/ml
API Reference

JavaScript Machine Learning APIs

Browse @kanaries/ml JavaScript and TypeScript ML APIs: clustering, linear models, trees, ensembles, SVM, decomposition, metrics, and preprocessing utilities.

View as Markdown

Module overview

This page is the entry point to the full @kanaries/ml API catalog. It helps JavaScript and TypeScript teams choose the right algorithm family before diving into individual estimators such as K-Means, Logistic Regression, Isolation Forest, PCA, or k-Nearest Neighbors.

Use this catalog when you already know the kind of problem you need to solve, such as:

  • classification or regression on tabular data
  • clustering or segmentation without labels
  • anomaly detection on product, telemetry, or transaction data
  • dimensionality reduction for embeddings, charts, or preprocessing
  • utility workflows such as non-blocking execution in browser or Node.js apps

JavaScript implementation

@kanaries/ml provides a scikit-learn-like machine learning API for JavaScript and TypeScript so teams can build ML workflows directly in browser applications and Node.js services. Instead of treating ML as a separate Python-only layer, you can keep feature engineering, inference logic, interactive visualizations, and product code inside the same JS stack.

This is especially useful when someone searches for "machine learning in JavaScript", "TypeScript machine learning APIs", or "scikit-learn for JavaScript" and needs a practical module map rather than a single algorithm page.

Quick navigation

  • Pipeline: chain preprocessing, ColumnTransformer, FeatureUnion, and estimators without train/test leakage.
  • Model Serialization: save and load fitted models and pipelines with toJSON(), loadModel(), and fromJSON().
  • Clusters: segment unlabeled data with K-Means, E-Means, Birch, Affinity Propagation, HDBSCAN, and related methods.
  • Mixture Models: fit soft probabilistic clusters and densities with GaussianMixture and BayesianGaussianMixture.
  • Decomposition: reduce dimensions or separate latent structure with PCA, Kernel PCA, FastICA, NMF, Incremental PCA, Sparse PCA, and Truncated SVD.
  • Discriminant Analysis: classify and project data with closed-form LDA and QDA.
  • Ensemble: use Isolation Forest, AdaBoost, random forest, gradient boosting, XGBoost, and bagging models for anomaly detection, classification, and regression.
  • Calibration: calibrate classifier probabilities with Platt scaling (sigmoid) or isotonic regression via CalibratedClassifierCV.
  • Multiclass: extend binary classifiers to multiclass tasks with OneVsRestClassifier and OneVsOneClassifier.
  • Isotonic Regression: fit non-parametric monotonic 1D curves via Pool-Adjacent-Violators (IsotonicRegression).
  • Dummy Baselines: sanity-check classifiers and regressors with DummyClassifier and DummyRegressor.
  • Covariance: estimate empirical, shrunk, robust, or sparse inverse covariance.
  • Feature Selection: select columns with model importance, recursive elimination, or univariate scores.
  • Feature Extraction: turn raw text into sparse count and TF-IDF features.
  • Imputation: estimate correlated numeric values missing from feature matrices.
  • Linear: use classical, robust, Bayesian, quantile, and generalized linear models.
  • Kernel Methods: fit kernel ridge regression or density estimates, or approximate a kernel with random Fourier features and Nyström landmarks.
  • Gaussian Processes: estimate a continuous target with uncertainty or predict class probabilities on small datasets.
  • Cross Decomposition: model paired blocks with PLS Regression and CCA.
  • Random Projection: reduce dimensions with Gaussian or sparse Johnson-Lindenstrauss maps.
  • Compose: wrap regression targets in invertible preprocessing transformations.
  • Metrics: evaluate classification, regression, clustering, curves, and distance functions.
  • Manifold: build lower-dimensional embeddings for visualization and neighborhood analysis.
  • Neighbors: run k-nearest neighbors and fast nearest-neighbor search structures.
  • SVM: train support vector models for classification and regression.
  • Tree: use interpretable decision tree and extra tree models.
  • Bayes: apply naive Bayes models to binary or categorical features.
  • Neural Network: learn compact representations with Bernoulli RBM.
  • Semi-Supervised: spread labels through partially labeled datasets.
  • Multi-Output: predict related label or regression targets with estimator chains.
  • Datasets: generate seeded synthetic datasets (makeBlobs, makeMoons, makeCircles, makeClassification, makeRegression).
  • Sparse Data (CSRMatrix): store and slice high-dimensional sparse feature matrices efficiently.
  • Utils: use preprocessing, sampling, model selection, statistics, and async workflow helpers.
  • Algebra: use lightweight matrix helpers such as transpose, determinants, and inverse.
  • KMath: compute lightweight descriptive statistics.

Detailed module guide

How to choose a module

  1. Start from the task type: classification, regression, clustering, anomaly detection, embedding, or workflow support.
  2. Open the matching module page and compare one simple baseline against one stronger alternative.
  3. Read the algorithm-specific guidance to balance model quality with browser latency, Node.js throughput, and implementation complexity.
  1. If you are new to the library, start with Linear, Tree, or Clusters.
  2. Move to Ensemble and SVM when simple baselines are not expressive enough.
  3. Use Metrics, Decomposition, Manifold, and Utils to improve evaluation, preprocessing, visualization, and application integration.

sklearn-compatible naming aliases

Canonical sklearn spellings are available alongside the legacy names so existing JavaScript code remains compatible:

Canonical exportLegacy exportNamespace
DBSCANDBScanClusters
HDBSCANHDBScanClusters
KNeighborsClassifierKNearestNeighborsNeighbors
LDALinearDiscriminantAnalysisDiscriminantAnalysis
QDAQuadraticDiscriminantAnalysisDiscriminantAnalysis
LLELocallyLinearEmbeddingManifold

Both names reference the same constructor; aliases do not duplicate estimator coverage or change serialized model names.