@kanaries/ml
API Reference/Linear Models

Polynomial Regression

Fit nonlinear numeric trends with the PolynomialRegression JavaScript and TypeScript implementation in @kanaries/ml for browser and Node.js regression workflows.

View as Markdown

Algorithm overview

Polynomial regression expands each numeric feature into powers of that feature, then fits a linear model on the expanded matrix. It is useful when a linear baseline is too simple but the target still follows a smooth curve.

Use it for small numeric regression problems where the degree of curvature is known or easy to tune.

JavaScript implementation

@kanaries/ml provides Linear.PolynomialRegression as a JavaScript estimator with fit and predict. It runs in browser or Node.js and keeps polynomial feature expansion inside the model.

Interactive polynomial regression playground

Adjust the polynomial degree, data shape, and noise below. The curve is fitted live with Linear.PolynomialRegression; click the chart to test how an added observation changes the fit.

Live browser model

PolynomialRegression playground

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

Fitted with @kanaries/ml
-3-2-10123-2.3-1.2-0.10.92.0feature xtarget y
prediction training holdout your points
Train RMSE0.274
Holdout RMSE0.407
Holdout R²0.175
Custom points0

Quick start example

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

const X = [[0], [1], [2], [3]];
const y = [1, 2, 5, 10];

const model = new Linear.PolynomialRegression({ degree: 2 });
model.fit(X, y);
const pred = model.predict([[4]]);
console.log(pred);

Detailed API reference

new Linear.PolynomialRegression(props?: { degree?: number })

Options:

  • degree?: number, default 2. Must be an integer greater than or equal to 1.

Methods:

  • fit(X: number[][], Y: number[]): void
  • predict(X: number[][]): number[]

The implementation expands every input feature to powers from 1 through degree, fits ordinary least squares, and stores an intercept plus coefficients internally.