在建模过程中多次用到过sklearn.preprocessing.PolynomialFeatures,可以理解为专门生成多项式特征,并且多项式包含的是相互影响的特征集,比如:一个输入样本是2维的。形式如[a,b] ,则二阶多项式的特征集如下[1,a,b,a^2,ab,b^2]。
官网文档:http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.PolynomialFeatures.html
参数:
degree : integer,多项式阶数,默认为2;
interaction_only : boolean, default = False,如果值为true(默认是false),则会产生相互影响的特征集;
include_bias : boolean,是否包含偏差列。
示例:
[python]view plaincopy
>>> X = np.arange(6).reshape(3, 2)
>>> X
array([[0, 1],
[2, 3],
[4, 5]])
>>> poly = PolynomialFeatures(2) #设置多项式阶数为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)#默认的阶数是2,同时设置交互关系为true
>>> poly.fit_transform(X)
array([[1., 0., 1., 0.],
[1., 2., 3., 6.],
[1., 4., 5., 20.]])
上面的数组中,每一行是一个list。比如[0,1] 类似与上面的[a,b]。好的现在它的多项式输出矩阵就是[1,a,b,a^2,ab,b^2]。所以就是下面对应的[1,0,1,0,0,1]。现在将interaction_only=True。这时就是只找交互作用的多项式输出矩阵。例如[a,b]的多项式交互式输出[1,a,b,ab]。不存在自己与自己交互的情况如;a^2或者a*b^2之类的。
作者:xxyytt
链接:https://www.jianshu.com/p/4ca64b3701cc
相关推荐
conditional compilation (using special preprocessing directives, you can include or exclude parts of the program according to various conditions); and line control (if you use a program to combine or...
using wave file to compute preprocessing, short term energy, zero crossing rate, signal_ste, stzcr
python库。 资源全名:Keras_Preprocessing-1.0.4-py2.py3-none-any.whl
python库,解压后可用。 资源全名:microt_preprocessing-0.0.11-py3-none-any.whl
资源来自pypi官网。 资源全名:microt_preprocessing-0.0.22-py3-none-any.whl
资源来自pypi官网。 资源全名:microt_preprocessing-0.0.11-py3-none-any.whl
- sklearn.preprocessing.MinMaxScaler:用于数据归一化 - sklearn.metrics.mean_squared_error和sklearn.metrics.r2_score:用于评估模型性能 - keras:用于构建神经网络模型 - numpy:用于数值计算 - math....
大数据辅助插件下载keras_preprocessing1.0.1,放这里大家随便下载,绝对好用,不限制
python库。 资源全名:microt_preprocessing-0.0.18-py3-none-any.whl
资源分类:Python库 所属语言:Python 资源全名:nlp_preprocessing-0.1.6-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
Minimal preprocessing of the data is required, but the architecture of the network is highly constrained and specifically designed for the task. The input of the network consists of size-normalized ...
sklearn:sklearn.preprocessing的MinMaxScaler简介、使用方法之详细攻略 目录 MinMaxScaler简介 MinMaxScaler函数解释 MinMaxScaler底层代码 MinMaxScaler的使用方法 1、基础案例 MinMaxScaler简介 MinMaxScaler...
资源分类:Python库 所属语言:Python 资源全名:categorical_encoding-0.2.0-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
python-machine-learning-cookbook-preprocessing oreilly 英文 epub格式
Data preprocessing.pdf
Matlab集成的c代码表中的内容 团队详情 抽象的 使用的算法3.1回归3.1.1线性回归...sklearn.preprocessing.PolynomialFeatures 5.2 sklearn.linear_model 5.2.1 sklearn.linear_model.LinearRegressionion 5.2.2 skle
dataPreprocessing.py