preprocessing.PolynomialFeatures

Generate polynomial and interaction features. Generate a new feature matrix consisting of all polynomial combinations of the features with degree less than or equal to the specified degree. For example, if an input sample is two dimensional and of the form [a, b], the degree-2 polynomial features are [1, a, b, a^2, ab, b^2].

Usage

import { PolynomialFeatures } from 'machinelearn/preprocessing';
const poly = new PolynomialFeatures();
const X = [[0, 1], [2, 3], [4, 5]];
poly.transform(X);
// Result:
// [ [ 1, 0, 1, 0, 0, 1 ],
// [ 1, 2, 3, 4, 6, 9 ],
// [ 1, 4, 5, 16, 20, 25 ] ]

Constructors

Methods

Constructors


constructor

new PolynomialFeatures(__namedParameters: `object`)

Defined in preprocessing/data.ts:603

Parameters:

ParamTypeDefaultDescription
options.degreenumber2The degree of the polynomial features. Default = 2.

Returns: PolynomialFeatures

Methods


λ transform

Transforms the input data

Defined in preprocessing/data.ts:629

Parameters:

ParamTypeDefaultDescription
Xnumber[][]nulla matrix

Returns:

number[][]