其他分享
首页 > 其他分享> > 特征筛选伪代码

特征筛选伪代码

作者:互联网

xgb=XGB(trial=False)
trainded_model=xgb.train(trainset,date_name='date',label_name='target')
pred,gt=xgb.test(testset,trainded_model,date_name='date',label_name='target')
base_mse=evaluation(pred.values ,gt.values ,method='mse')
print('base_mse:',base_mse)

feas=['ws10','wd10','ws30','wd30','ws50','wd50','ws70','wd70','TEMP','HUMID']

while True:
l1=len(feas)
for fea in feas:
xgb=XGB(trial=False)
trainset_copy=trainset.copy()
testset_copy=testset.copy()
del trainset_copy[fea]
del testset_copy[fea]
trainded_model=xgb.train(trainset_copy,date_name='date',label_name='target')
pred,gt=xgb.test(testset_copy,trainded_model,date_name='date',label_name='target')
mse=evaluation(pred.values ,gt.values ,method='mse')
print('mse:',mse)
if mse<base_mse:
feas.remove(fea)###当找到能降低mse的无用特征时,永久删除该特征,然后break,开启下一段循环
break
if len(feas)==l1:###当找不到无用特征,feas数量收敛时,断开while True
print(feas)
break

标签:feas,name,特征,代码,xgb,date,筛选,copy,mse
来源: https://www.cnblogs.com/chentianyu/p/16157867.html