# @rainij/polynomial-regression-js

1.3.1 • Public • Published

# polynomial-regression-js

polynomial-regression-js is a typescript library for linear and polynomial regression in multiple variables. It provides a class PolynomialRegressor for multivariate polynomial regression and a class PolynomialFeatures for transforming input features [x1, x2, ..., xn] into polynomial features [..., x1k1 x2k2 ... xnkn, ...].

There is an old version of the library `regression-multivariate-polynomial ` which is still widely used. If you use it I encourage you to switch from the latest version of the old library to the oldest version of the new library. They are supposed to be identical.

# Installation

`npm install --save @rainij/polynomial-regression-js`

# Usage

## PolynomialRegressor

```import { PolynomialRegressor } from '@rainij/polynomial-regression-js';

// Y0 = X0^2 + 2*X0*X1, Y1 = X1^2 + 5*X0 + 1
// Quadratric functions with two inputs need (at least) seven supporting points:
const x = [[0, 0], [1, 0], [2, 0], [0, 1], [0, 2], [1, 1], [2, 2]];
const y = [[0, 1], [1, 6], [4, 11], [0, 2], [0, 5], [3, 7], [12, 15]];

// Search for a polynomial model of degree = 2.
const model = new PolynomialRegressor(2);
model.fit(x,y) // Training
console.log(model.predict([[3, 3]]));
// [ [27, 25] ]```

## PolynomialFeatures

```import { PolynomialFeatures } from '@rainij/polynomial-regression-js';

const x = [[3, 2]] // Two features: [[a, b]]

// Generate polynomial features up to degree 3
let polyFeatures = new PolynomialFeatures(3);

console.log(polyFeatures.fitTransform(x));
// [ [27, 18, 9, 12, 6, 3, 8, 4, 2, 1] ]
// That is: [ [a^3, a^2b, ab^2, ab, a, b^3, b^2, b, 1] ]```

# API

API documentation built by TypeDoc.

MIT

## Package Sidebar

### Install

`npm i @rainij/polynomial-regression-js`

### Repository

github.com/rainij/polynomial-regression-js

### Homepage

rainij.github.io/polynomial-regression-js

1,579

1.3.1

MIT

28.9 kB

16