PolynomialFeatures使用

PolynomialFeatures

sklearn.preprocessing.PolynomialFeatures 用法
sklearn中数据预处理过程中的多项式特征构造工具包。
eg:[x1,x2] -> [1,x1,x2,x12,x1*x2,x22]输入一个二维样本。产生二阶多项式特征。

1.参数理解:(一共只有3个参数)

  • degree : integer
    The degree of the polynomial features. Default = 2.
    多项式的阶数,一般默认是2。
  • interaction_only : boolean, default = False
    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.).
    如果值为true(默认是false),则会产生相互影响的特征集。
  • include_bias : boolean
    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).
    是否包含偏差列

2.属性

  • powers_ : array, shape (n_input_features, n_output_features)
    powers_[i, j] is the exponent of the jth input in the ith output.
  • n_input_features_ : int
    The total number of input features.
    输入特征的个数
  • n_output_features_ : int
    The total number of polynomial output features. The number of output features is computed by iterating over all suitably sized combinations of input features.
    输出多项式的特征个数。它的计算是通过遍历所有的适当大小的输入特征组合。

3.方法

  1. fit(X, y=None)
    Compute number of output features.
    计算输出特征的个数
  2. fit_transform(X, y=None, **fit_params)
    Fit to data, then transform it.

你可能感兴趣的:(PolynomialFeatures使用)