Python 2.7
IDE Pychrm 5.0.3
sci-kit learn 0.18.1
前言
抖了个机灵,不要来打我,这是没有理论依据证明的,只是模型测试出来的确有效,并且等待时间下降(约)为原来的十分之一!!刺不刺激,哈哈哈。
原理
基本思想:先找重点在细分,再细分,伸缩Flexible你怕不怕。以下简称这种方法为FCV
伪代码
原理很好理解,直接上伪代码,懒得打字,上手稿
这里写图片描述
FCV测试时间
以GBDT为例,我测试了下,参数 n_estimators从190到300,max_depth从2到9,CV=3
普通的GridSerachCV总共fit了11073=2310次,耗时1842min,也就是30.7个小时,得出最优参数n_estimators=289,max_depth=3
FCV总共总共fit了345次,跑了166min,也就是2.8小时,得出最优参数n_estimators=256,max_depth=3
时间方面,相差11倍,那么效果呢,请看下面的CV得分
FCV测试效果
选取了GBDT,RF,XGBOST,SVM做了交叉验证比较,同一算法之间保持相同参数。
GBDT的测试结果
clf1 = GradientBoostingClassifier(max_depth=3,n_estimators=289)#.fit(train_data,train_label)
score1 = model_selection.cross_val_score(clf1,train_data,train_label,cv=5)
print score1
-------------------------------------
clf2 = GradientBoostingClassifier(max_depth=3,n_estimators=256)#.fit(train_data,train_label)
score2 = model_selection.cross_val_score(clf2,train_data,train_label,cv=5)
print score2
------------------------------------
# 查看两种方法的交叉验证效果
#传统方法CV=5:[ 0.79807692 0.82038835 0.80684597 0.76108374 0.78163772]
#改进方法CV=5:[ 0.79567308 0.82038835 0.799511 0.76847291 0.78411911]
---------------------------------------
#传统方法CV=10:[ 0.83333333 0.78571429 0.84615385 0.7961165 0.81067961 0.80097087 0.77227723 0.78109453 0.785 0.74111675]
#FCV方法CV=10:[ 0.85238095 0.78095238 0.85096154 0.7961165 0.81553398 0.7961165 0.76732673 0.79104478 0.795 0.75126904]
Xgboost的测试结果
clf1 = XGBClassifier(max_depth=6,n_estimators=200)#.fit(train_data,train_label)
score1 = model_selection.cross_val_score(clf1,train_data,train_label,cv=5)
print score1
clf2 = XGBClassifier(max_depth=4,n_estimators=292)#.fit(train_data,train_label)
score2 = model_selection.cross_val_score(clf2,train_data,train_label,cv=5)
print score2
-----------------------------
#传统方法CV=5:[ 0.79086538 0.83737864 0.80929095 0.79310345 0.7866005 ]
#FCV方法CV=5:[ 0.80288462 0.84466019 0.8190709 0.79064039 0.78163772]
RF的测试结果
注:由于RF的特殊性,选择样本的方式和选择特征的方式都随机,所以即使交叉验证,效果也不是稳定的,就像我在服务器上跑多进程和笔记本上跑同一个程序,出来的最佳值一个是247,一个是253,并不是说都