# PolynomialFeatures

### *class* cuml.preprocessing.PolynomialFeatures(\*args, \*\*kwargs)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L1501)

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

* **Parameters:**
  **degree**
  : The degree of the polynomial features. Default = 2.

  **interaction_only**
  : If true, only interaction features are produced: features that are
    products of at most `degree` *distinct* input features (so not
    `x[1] ** 2`, `x[0] * x[2] ** 3`, etc.).

  **include_bias**
  : If 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).

  **order**
  : Order of output array in the dense case. ‘F’ order is faster to
    compute, but may slow down subsequent estimators.
* **Attributes:**
  **powers_**
  : powers_[i, j] is the exponent of the jth input in the ith output.

  **n_input_features_**
  : The total number of input features.

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

### Methods

| [`fit`](#cuml.preprocessing.PolynomialFeatures.fit)(X[, y])                             | Compute number of output features.           |
|------------------------------------------------------------------------------------------|----------------------------------------------|
| [`get_feature_names_out`](#cuml.preprocessing.PolynomialFeatures.get_feature_names_out)([input_features]) | Get output feature names for transformation. |
| [`transform`](#cuml.preprocessing.PolynomialFeatures.transform)(X)                            | Transform data to polynomial features        |

### Notes

Be aware that the number of features in the output array scales
polynomially in the number of features of the input array, and
exponentially in the degree. High degrees can cause overfitting.

### Examples

```pycon
>>> import numpy as np
>>> from cuml.preprocessing import PolynomialFeatures
>>> X = np.arange(6).reshape(3, 2)
>>> X
array([[0, 1],
       [2, 3],
       [4, 5]])
>>> poly = PolynomialFeatures(2)
>>> poly.fit_transform(X)
array([[ 1.,  0.,  1.,  0.,  0.,  1.],
       [ 1.,  2.,  3.,  4.,  6.,  9.],
       [ 1.,  4.,  5., 16., 20., 25.]])
>>> poly = PolynomialFeatures(interaction_only=True)
>>> poly.fit_transform(X)
array([[ 1.,  0.,  1.,  0.],
       [ 1.,  2.,  3.,  6.],
       [ 1.,  4.,  5., 20.]])
```

<!-- !! processed by numpydoc !! -->

#### fit(X, y=None) → [PolynomialFeatures](#cuml.preprocessing.PolynomialFeatures)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L1637)

Compute number of output features.

* **Parameters:**
  **X**
  : The data.
* **Returns:**
  **self**

<!-- !! processed by numpydoc !! -->

#### fit_transform(X, y=None, \*\*fit_params)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/utils/skl_dependencies.py#L42)

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params
and returns a transformed version of X.

* **Parameters:**
  **X**

  **y**
  : Target values.

  **\*\*fit_params**
  : Additional fit parameters.
* **Returns:**
  **X_new**
  : Transformed array.

<!-- !! processed by numpydoc !! -->

#### get_feature_names_out(input_features=None)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L1607)

Get output feature names for transformation.

* **Parameters:**
  **input_features**
  : Input feature names.
* **Returns:**
  **feature_names_out**
  : Transformed feature names.

<!-- !! processed by numpydoc !! -->

#### get_params(deep=True)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L191)

Returns a dict of all params owned by this class. If the child class
has appropriately overridden the `_get_param_names` method and does not
need anything other than what is there in this method, then it doesn’t
have to override this method

<!-- !! processed by numpydoc !! -->

#### set_params(\*\*params)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L200)

Accepts a dict of params and updates the corresponding ones owned by
this class. If the child class has appropriately overridden the
`_get_param_names` method and does not need anything other than what is,
there in this method, then it doesn’t have to override this method

<!-- !! processed by numpydoc !! -->

#### transform(X)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L1661)

Transform data to polynomial features

* **Parameters:**
  **X**
  : The data to transform, row by row.
    <br/>
    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.
    <br/>
    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:**
  **XP**
  : The matrix of features, where NP is the number of polynomial
    features generated from the combination of inputs.

<!-- !! processed by numpydoc !! -->
