@kanaries/ml
API Reference/Linear Models

Poisson, Gamma, and Tweedie Regression

Model counts and positive skewed targets with PoissonRegressor, GammaRegressor, and TweedieRegressor in browser or Node.js.

View as Markdown

Generalized linear models

Algorithm overview

Generalized linear models connect a linear predictor to non-Gaussian targets. Poisson regression is suited to counts, Gamma regression to positive continuous values, and Tweedie regression spans several variance relationships through its power parameter.

JavaScript implementation

The @kanaries/ml implementations use regularized Newton updates and a guarded line search, with log links for positive-mean families.

Interactive generalized linear model playground

Switch between Poisson, Gamma, and Tweedie regression, tune regularization, and add positive-valued observations. The prediction is refitted live with the chosen Linear estimator.

Live browser model

Poisson playground

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

Fitted with @kanaries/ml
-3-2-10123-0.31.22.74.25.7feature xtarget y
prediction training holdout your points
Train RMSE0.187
Holdout RMSE0.391
Holdout R²0.915
Custom points0

Quick start

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

const model = new Linear.PoissonRegressor({ alpha: 0.1 });
model.fit([[0], [1], [2]], [1, 2, 4]);
console.log(model.predict([[3]]));

Detailed API reference

All three accept alpha, fitIntercept, maxIter, and tol. Poisson and Gamma regression use their canonical log link. TweedieRegressor additionally accepts power (values in (0, 1) are undefined) and link: 'auto' | 'identity' | 'log'. Fitted models expose coef, intercept, and nIter.