Documentation
Classes
PolynomialFeatures

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].

Read more in the User Guide.

Python Reference (opens in a new tab)

Constructors

constructor()

Signature

new PolynomialFeatures(opts?: object): PolynomialFeatures;

Parameters

NameTypeDescription
opts?object-
opts.degree?numberIf a single int is given, it specifies the maximal degree of the polynomial features. If a tuple (min\_degree, max\_degree) is passed, then min\_degree is the minimum and max\_degree is the maximum polynomial degree of the generated features. Note that min\_degree=0 and min\_degree=1 are equivalent as outputting the degree zero term is determined by include\_bias. Default Value 2
opts.include_bias?booleanIf true (default), then include a bias column, the feature in which all polynomial powers are zero (i.e. a column of ones - acts as an intercept term in a linear model). Default Value true
opts.interaction_only?booleanIf true, only interaction features are produced: features that are products of at most degree distinct input features, i.e. terms with power of 2 or higher of the same input feature are excluded: Default Value false
opts.order?"C" | "F"Order of output array in the dense case. 'F' order is faster to compute, but may slow down subsequent estimators. Default Value 'C'

Returns

PolynomialFeatures

Defined in: generated/preprocessing/PolynomialFeatures.ts:25 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/preprocessing/PolynomialFeatures.ts:23 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/preprocessing/PolynomialFeatures.ts:22 (opens in a new tab)

_py

PythonBridge

Defined in: generated/preprocessing/PolynomialFeatures.ts:21 (opens in a new tab)

id

string

Defined in: generated/preprocessing/PolynomialFeatures.ts:18 (opens in a new tab)

opts

any

Defined in: generated/preprocessing/PolynomialFeatures.ts:19 (opens in a new tab)

Accessors

feature_names_in_

Names of features seen during fit. Defined only when X has feature names that are all strings.

Signature

feature_names_in_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/preprocessing/PolynomialFeatures.ts:370 (opens in a new tab)

n_features_in_

Number of features seen during fit.

Signature

n_features_in_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/preprocessing/PolynomialFeatures.ts:343 (opens in a new tab)

n_output_features_

The total number of polynomial output features. The number of output features is computed by iterating over all suitably sized combinations of input features.

Signature

n_output_features_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/preprocessing/PolynomialFeatures.ts:397 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/preprocessing/PolynomialFeatures.ts:58 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/preprocessing/PolynomialFeatures.ts:62 (opens in a new tab)

Methods

dispose()

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Signature

dispose(): Promise<void>;

Returns

Promise<void>

Defined in: generated/preprocessing/PolynomialFeatures.ts:119 (opens in a new tab)

fit()

Compute number of output features.

Signature

fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe data.
opts.y?anyNot used, present here for API consistency by convention.

Returns

Promise<any>

Defined in: generated/preprocessing/PolynomialFeatures.ts:136 (opens in a new tab)

fit_transform()

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit\_params and returns a transformed version of X.

Signature

fit_transform(opts: object): Promise<any[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]Input samples.
opts.fit_params?anyAdditional fit parameters.
opts.y?ArrayLikeTarget values (undefined for unsupervised transformations).

Returns

Promise<any[]>

Defined in: generated/preprocessing/PolynomialFeatures.ts:178 (opens in a new tab)

get_feature_names_out()

Get output feature names for transformation.

Signature

get_feature_names_out(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.input_features?anyInput features.

Returns

Promise<any>

Defined in: generated/preprocessing/PolynomialFeatures.ts:229 (opens in a new tab)

init()

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Signature

init(py: PythonBridge): Promise<void>;

Parameters

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/preprocessing/PolynomialFeatures.ts:71 (opens in a new tab)

set_output()

Set output container.

See Introducing the set_output API for an example on how to use the API.

Signature

set_output(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.transform?"default" | "pandas"Configure output of transform and fit\_transform.

Returns

Promise<any>

Defined in: generated/preprocessing/PolynomialFeatures.ts:269 (opens in a new tab)

transform()

Transform data to polynomial features.

Signature

transform(opts: object): Promise<ArrayLike>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe data to transform, row by row. Prefer CSR over CSC for sparse input (for speed), but CSC is required if the degree is 4 or higher. If the degree is less than 4 and the input format is CSC, it will be converted to CSR, have its polynomial features generated, then converted back to CSC. If the degree is 2 or 3, the method described in “Leveraging Sparsity to Speed Up Polynomial Feature Expansions of CSR Matrices Using K-Simplex Numbers” by Andrew Nystrom and John Hughes is used, which is much faster than the method used on CSC input. For this reason, a CSC input will be converted to CSR, and the output will be converted back to CSC prior to being returned, hence the preference of CSR.

Returns

Promise<ArrayLike>

Defined in: generated/preprocessing/PolynomialFeatures.ts:304 (opens in a new tab)