默认参数下:
defull = xgboost.DMatrix(data.data,data.target)
param = {'silent':True,'obj':'reg:linear','subsample':1,
'max_depth':6,'eta':0.3,'gamma':0,'lambda':1,
'alpha':0,'colsample_bytree':1,'colsample_bylevel':1,
'colsample_bynode':1,'nfold':5}
num_round = 200
time_start = time()
estimator = xgboost.cv(param,defull,num_round)
print(datetime.datetime.fromtimestamp(time()-time_start).strftime("%M:%S:%f"))
# 学习曲线
fig,ax = plt.subplots(1,figsize=(20,8))
ax.grid()
ax.plot(range(1,201),estimator.iloc[:,0],label='train')
ax.plot(range(1,201),estimator.iloc[:,2],label='test')
ax.set_ylim(top=5)
ax.legend()
plt.show()
模型存在明显过拟合的现象。
后续调参会发现,max——depth和eta对模型的过拟合现象会有最明显的改善,而使用'colsample_bylevel':0.4时,效果虽然只有轻微的改善,但降低了运行时间,这里对'colsample_bylevel'也进行调整
模型保存和读取:
其它参数: