@kanaries/ml
API Reference/Linear Models

Bayesian Ridge and ARD Regression

Run BayesianRidge and sparse ARDRegression in JavaScript or TypeScript with posterior uncertainty and sklearn-style APIs.

View as Markdown

Bayesian linear regression

Algorithm overview

Bayesian linear models place probability distributions over coefficients. They are useful when you want regularized predictions plus uncertainty, or automatic relevance determination that prunes weak features.

JavaScript implementation

BayesianRidge learns a shared coefficient precision and supports predictStd. ARDRegression learns one precision per feature and zeros coefficients whose precision crosses thresholdLambda.

Interactive Bayesian regression playground

Compare Bayesian Ridge and ARD Regression while changing the data and iteration budget. The live curve and holdout metrics come from the selected @kanaries/ml model running in your browser.

Live browser model

Bayesian Ridge playground

Adjust the data and model, then click the chart to add a training observation.

Fitted with @kanaries/ml
-3-2-10123-1.9-0.90.01.01.9feature xtarget y
prediction training holdout your points
Train RMSE0.703
Holdout RMSE0.700
Holdout R²-1.445
Custom points0

Quick start

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

const X = [[0], [1], [2], [3]];
const y = [1, 3, 5, 7];
const model = new Linear.BayesianRidge();
model.fit(X, y);
const mean = model.predict([[4]]);
const standardDeviation = model.predictStd([[4]]);
console.log({ mean, standardDeviation });

Detailed API reference

Both estimators accept maxIter, tol, Gamma-prior hyperparameters, and fitIntercept, and expose coef, intercept, alpha, lambda, sigma, and nIter.