mojolearn.PolynomialFeatures#

class mojolearn.PolynomialFeatures(degree=2, *, interaction_only=False, include_bias=True, order='C')[source]#

Bases: _PrepBase

Generate polynomial and interaction features.

Follows scikit-learn’s PolynomialFeatures, with the same output column order: the bias column, then the products of input columns degree by degree (combinations with replacement, or without when interaction_only). Input and output are float32.

Parameters:
  • degree (int or tuple of (int, int), default 2) – Largest degree, or (min_degree, max_degree). Negative values or min_degree > max_degree raise ValueError.

  • interaction_only (bool, default False) – Only products of distinct columns (no powers of one column).

  • include_bias (bool, default True) – Include the constant column of ones.

  • order ({‘C’, ‘F’}, default ‘C’) – Memory order of the output array; 'F' returns the same values column-major.

Variables:
  • powers_ (array of shape (n_output_features_, n_features_in_)) – Exponent of each input column in each output column.

  • n_features_in_ (int) – Number of columns seen in fit.

  • n_output_features_ (int) – Number of output columns.

  • numeric_mode_ (str) – Numeric mode at fit time; transform runs in the same mode.

Examples

>>> import numpy as np, mojolearn
>>> X = np.arange(6, dtype=np.float32).reshape(3, 2)
>>> mojolearn.PolynomialFeatures(degree=2).fit_transform(X)
__init__(degree=2, *, interaction_only=False, include_bias=True, order='C')[source]#

Methods

fit(X[, y])

fit_transform(X[, y])

Fit to X, then transform X.

get_params([deep])

Return the constructor parameters as a dict.

set_params(**params)

Set constructor parameters.

transform(X)