Python Scikit学习GridSearchCV AUC性能
我使用GridSearchCV来识别随机森林分类器的最佳参数集Python Scikit学习GridSearchCV AUC性能,python,scikit-learn,cross-validation,grid-search,auc,Python,Scikit Learn,Cross Validation,Grid Search,Auc,我使用GridSearchCV来识别随机森林分类器的最佳参数集 PARAMS = { 'max_depth': [8,None], 'n_estimators': [500,1000] } rf = RandomForestClassifier() clf = grid_search.GridSearchCV(estimator=rf, param_grid=PARAMS, scoring='roc_auc', cv=5, n_jobs=4) clf.fit(data, labe
PARAMS = {
'max_depth': [8,None],
'n_estimators': [500,1000]
}
rf = RandomForestClassifier()
clf = grid_search.GridSearchCV(estimator=rf, param_grid=PARAMS, scoring='roc_auc', cv=5, n_jobs=4)
clf.fit(data, labels)
其中数据和标签分别是完整数据集和相应的标签
现在,我将GridSearchCV(来自clf.grid\u scores\uuu
)返回的性能与“手动”AUC估计值进行了比较:
aucs = []
for fold in range (0,n_folds):
probabilities = []
train_data,train_label = read_data(train_file_fold)
test_data,test_labels = read_data(test_file_fold)
clf = RandomForestClassifier(n_estimators = 1000,max_depth=8)
clf = clf.fit(train_data,train_labels)
predicted_probs = clf.predict_proba(test_data)
for value in predicted_probs:
for k, pr in enumerate(value):
if k == 1:
probabilities.append(pr)
fpr, tpr, thresholds = metrics.roc_curve(test_labels, probabilities, pos_label=1)
fold_auc = metrics.auc(fpr, tpr)
aucs.append(fold_auc)
performance = np.mean(aucs)
其中,我手动将数据预拆分为训练集和测试集(相同的5 CV方法)
GridSearchCV
返回的AUC值始终高于手动计算的AUC值(例如,0.62 vs.0.70),当对RandomForest
使用相同参数时。
我知道不同的训练和测试组合可能会给你带来不同的表现,但在测试GridSearchCV的100次重复时,这种情况经常发生。有趣的是,如果我使用
acuarcy
而不是roc_auc
作为评分指标,那么绩效差异是最小的,并且可能与我使用不同的训练和测试集有关。之所以会出现这种情况,是因为GridSearchCV
的AUC值是以不同于使用metrics.roc\u curve
的方式估计的?GridSearchCV在提供“roc\u AUC”时使用的。使用它并检查是否仍然得到不同的分数。我仍然得到不同的分数,事实上这两种方法提供完全相同的AUC值。你检查了吗?