sklearn生成多项式
import numpy as np from sklearn.preprocessing import PolynomialFeatures #这哥用于生成多项式 x=np.arange(6).reshape(3,2) #生成三行二列数组 reg = PolynomialFeatures(degree=3) #这个3看下面的解释 reg.fit_transform(x)
x是下面这样:
我们发现规律如下:
Python生成多项式
编写实现函数如下:
def multi_feature(x,n): c = np.empty((x.shape[0],0)) #np.empty((3,1))并不会生成一个3行1列的空数组,np.empty((3,0))才会生成3行1列空数组 for i in range(n+1): for m in range(i,-1,-1): h=(x[:,0]**m) * (x[:,1]**(i-m)) c=np.c_[c,h] return c multi_feature(x,3)
和上面实现的一模一样
print('n=4时,sklearn的输出是:') reg = PolynomialFeatures(degree=4) print(reg.fit_transform(x)) print('\n') #对比 print('n=4时,函数的输出是:') print(multi_feature(x,4))
也是一样的,当然这个函数仅适用于2维数组,如果是n维数组,又该怎么实现呢?
风云阁资源网 Design By www.bgabc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
风云阁资源网 Design By www.bgabc.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 坣娜.1998-别恋【非常喜】【WAV+CUE】
- 《草原经典 最炫草原风 2CD》[WAV/分轨][980MB]
- 《不烧不选 经典国语极品珍藏》[WAV/分轨][500MB]
- 《绝对主打 流行原创金曲 2CD》[WAV分轨][1.1GB]
- 《赛博朋克2077》更新上线:支持AMD FSR3
- 《塞尔达传说:智慧的再现》提前半个月偷跑,引发玩家担忧
- 战锤40K星际战士2全职业介绍|全职业技能效果一览
- 陈百强《2006世纪10星·永恒篇[环球]》[WAV整轨]
- 【新世纪钢琴】VA-GoldenOctober(Piano)(金秋十月钢琴篇)【FLAC】
- 青稞荞麦《破茧》新生代组合[WAV+CUE]
- 因系统升级后出现BUG 《FF16》PS5完全版宣布延期
- 《黑神话:悟空》周伯通!大佬用左右手分别挑战两只虎先锋
- 《黑神话:悟空》攻击动作致敬《大话西游》:这也太帅了!
- 《星舰铳犬太阳系物语》游戏背景介绍
- 《战锤40K星际战士2》终极版有后续DLC说明