Programming Language: Python

Namespace/Package Name: sklearn.preprocessing

Class/Type: PolynomialFeatures

Method/Function: transform

Examples at hotexamples.com: 59

The `PolynomialFeatures` transformation in `sklearn.preprocessing` is used to generate polynomial and interaction features. It takes in the existing features and generates new features that are a combination of the input features, up to a specified degree. This can help in creating a more complex modeling system as it takes into account the interaction between different input features.

For example, if we have an input feature x and we apply a `PolynomialFeatures` transformation with degree 2, then the generated features would be x, x^2. Similarly, if we have two input features x and y and apply the transformation with degree 2, the generated features would be x, y, x^2, xy, y^2.

Here is an example code using `PolynomialFeatures` transformation:

This code will generate the following output array:

For example, if we have an input feature x and we apply a `PolynomialFeatures` transformation with degree 2, then the generated features would be x, x^2. Similarly, if we have two input features x and y and apply the transformation with degree 2, the generated features would be x, y, x^2, xy, y^2.

Here is an example code using `PolynomialFeatures` transformation:

from sklearn.preprocessing import PolynomialFeatures import numpy as np X = np.array([[3,4],[7,8]]) poly = PolynomialFeatures(degree=2) poly.fit_transform(X)

This code will generate the following output array:

array([[ 1., 3., 4., 9., 12., 16.], [ 1., 7., 8., 49., 56., 64.]])The first column represents the constant term, the second and third columns are the original features, and the remaining columns represent the interaction between the input features. Thus, `PolynomialFeatures` belongs to the `preprocessing` module of the `scikit-learn` library in Python.

Frequently Used Methods

Frequently Used Methods

Frequently Used Methods

Related

Related in langs