Covariance Estimation and Graphical Lasso
Estimate empirical, shrunk, Ledoit-Wolf, OAS, and sparse inverse covariance matrices in JavaScript or TypeScript.
View as MarkdownCovariance estimation
Algorithm overview
Covariance matrices describe joint feature variation and power Mahalanobis distance, Gaussian scoring, and graphical models. Shrinkage improves conditioning when data is limited; graphical lasso produces a sparse precision matrix.
JavaScript implementation
Choose EmpiricalCovariance for maximum-likelihood covariance, ShrunkCovariance for a fixed shrinkage amount, LedoitWolf or OAS for data-driven shrinkage, and GraphicalLasso for L1-regularized conditional dependence.
Quick start
import { Covariance } from '@kanaries/ml';
const X = [[0, 1], [1, 0], [2, 1], [3, 2]];
const model = new Covariance.OAS();
model.fit(X);
console.log(model.mahalanobis([[1, 1]]));Detailed API reference
Every estimator exposes location, covariance, and precision. The adaptive shrinkage classes expose shrinkageValue; GraphicalLasso uses block coordinate descent, accepts alpha, maxIter, tol, enetTol, and assumeCentered, and exposes nIter.
EllipticEnvelope Anomaly Detection
Detect multivariate outliers with robust covariance using the EllipticEnvelope JavaScript and TypeScript implementation in @kanaries/ml for browser and Node.js.
Feature Selection
Select informative columns in browser or Node.js machine-learning workflows with model-based, recursive, and univariate JavaScript feature selection in @kanaries/ml.