您好,欢迎来到华佗小知识。
搜索
您的当前位置:首页2.2sklearn.preprocessing.PolynomialFeatures生成交叉特征

2.2sklearn.preprocessing.PolynomialFeatures生成交叉特征

来源:华佗小知识

多项式生成函数:sklearn.preprocessing.PolynomialFeatures(degree=2, interaction_only=False, include_bias=True)
参数说明:

  • degree:默认为2,多项式次数(就同几元几次方程中的次数一样)
  • interaction_only:是否包含单个自变量**n(n>1)特征数据标识,默认为False,为True则表示去除与自己相乘的情况
  • include_bias:是否包含偏差标识,默认为True,为False则表示不包含偏差项
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(degree = 2)
poly.fit_transform(X)
array([[ 1.,  0.,  1.,  0.,  0.,  1.],
       [ 1.,  2.,  3.,  4.,  6.,  9.],
       [ 1.,  4.,  5., 16., 20., 25.]])
# 设置参数interaction_only = True,不包含单个自变量****n(n>1)特征数据
poly = PolynomialFeatures(degree = 2, interaction_only = True)
poly.fit_transform(X)
array([[ 1.,  0.,  1.,  0.],
       [ 1.,  2.,  3.,  6.],
       [ 1.,  4.,  5., 20.]])
# 再添加 设置参数include_bias= False,不包含偏差项数据
poly = PolynomialFeatures(degree = 2, interaction_only = True, include_bias=False)
poly.fit_transform(X)
array([[ 0.,  1.,  0.],
       [ 2.,  3.,  6.],
       [ 4.,  5., 20.]])

转载于:https://www.cnblogs.com/cjr0707/p/9750639.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo0.cn 版权所有 湘ICP备2023017654号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务