sklearn.preprocessing.PolynomialFeatures多项式特征

生成多项式和交互特征。

生成一个新的特征矩阵,该矩阵由度小于或等于指定度的特征的所有多项式组合组成。例如,如果输入样本是二维且格式为[a,b],则2阶多项式特征为[1,a,b,a ^ 2,ab,b ^ 2]。

参量 属性
度int,默认= 2多项式特征的程度。interact_only bool,默认为False如果为真,只有相互作用特征产生:是至多产品特征degree 不同输入特征(因此不是 ,等)。x[1] ** 2x[0] * x[2] ** 3include_bias bool,默认为True如果为True(默认值),则包括一个偏差列,该特征中所有多项式的幂均为零(即,一列的幂-在线性模型中充当拦截项)。顺序{‘C’,‘F’},默认='C’在密集情况下输出数组的顺序。“ F”阶的计算速度更快,但可能会减慢后续的估计量。0.21版中的新功能。 形状的powers_ ndarray(n_output_features,n_input_features)powers_ [i,j]是第i个输出中第j个输入的指数。n_input_features_ int输入功能的总数。n_output_features_ int多项式输出特征的总数。通过迭代所有适当大小的输入要素组合来计算输出要素的数量。

例子

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

计算输出要素的数量。

fit_transform(X [,y])

适合数据,然后对其进行转换。

get_feature_names([input_features])

返回输出要素的要素名称

get_params([深])

获取此估计量的参数。

set_params(**参数)

设置此估算器的参数。

transform(X)

将数据转换为多项式特征

猜你喜欢

转载自blog.csdn.net/m0_47256162/article/details/113495199