Generate polynomials and interactive features.
Generate a new feature matrix consisting of all polynomial combinations of features whose degree is less than or equal to the specified degree. For example, if the input sample is two-dimensional and the format is [a, b], the second-order polynomial feature is [1, a, b, a ^ 2, ab, b ^ 2].
Parameter | Attributes |
---|---|
Degree int, default = 2 The degree of polynomial features. interact_only bool, the default is False. If it is true, only interaction features are generated: at most product features degree and different input features (so not, etc.). x[1] ** 2x[0] * x[2] ** 3include_bias bool, the default is True. If True (the default value), a bias column is included. All polynomials in this feature have zero powers (ie, The power of a column-acts as an intercept term in the linear model). Order {'C','F'}, default='C' the order of output array in dense case. The calculation speed of the "F" order is faster, but it may slow down subsequent estimators. New features in version 0.21. | Shaped powers_ ndarray(n_output_features, n_input_features) powers_[i,j] is the index of the jth input in the i-th output. n_input_features_int Total number of input features. n_output_features_int The total number of polynomial output features. Calculate the number of output features by iterating all combinations of input features of appropriate size. |
example
>>> import numpy as np
>>> from sklearn.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.]])
fit(X [,y])
Calculate the number of output features.
fit_transform(X [,y])
Fit the data and then transform it.
get_feature_names([input_features])
Returns the feature name of the output feature
get_params([deep])
Get the parameters of this estimator.
set_params (** parameters)
Set the parameters of this estimator.
transform(X)
Convert data to polynomial features