class sklearn.preprocessing.PolynomialFeatures(degree=2, interaction_only=False, include_bias=True)
[source]
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: |
|
---|---|
Attributes: |
|
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.
See examples/linear_model/plot_polynomial_interpolation.py
>>> 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.]])
fit (X[, y]) | Compute number of output features. |
fit_transform (X[, y]) | Fit to data, then transform it. |
get_feature_names ([input_features]) | Return feature names for output features |
get_params ([deep]) | Get parameters for this estimator. |
set_params (**params) | Set the parameters of this estimator. |
transform (X) | Transform data to polynomial features |
__init__(degree=2, interaction_only=False, include_bias=True)
[source]
fit(X, y=None)
[source]
Compute number of output features.
Parameters: |
|
---|---|
Returns: |
|
fit_transform(X, y=None, **fit_params)
[source]
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: |
|
---|---|
Returns: |
|
get_feature_names(input_features=None)
[source]
Return feature names for output features
Parameters: |
|
---|---|
Returns: |
|
get_params(deep=True)
[source]
Get parameters for this estimator.
Parameters: |
|
---|---|
Returns: |
|
set_params(**params)
[source]
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter>
so that it’s possible to update each component of a nested object.
Returns: |
|
---|
transform(X)
[source]
Transform data to polynomial features
Parameters: |
|
---|---|
Returns: |
|
sklearn.preprocessing.PolynomialFeatures
© 2007–2018 The scikit-learn developers
Licensed under the 3-clause BSD License.
http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.PolynomialFeatures.html