我对cross_val_score中的'roc_auc'评分指标和可以直接导入并调用的roc_auc_score之间的差异感到困惑。
文档(http://scikit-learn.org/stable/modules/model_evaluation.html#scoring-parameter)表明,指定scoring ='roc_auc'将使用sklearn.metrics.roc_auc_score。但是,当我使用scoring ='roc_auc'实现GridSearchCV或cross_val_score时,与直接调用roc_auc_score时相比,我收到非常不同的数字。
以下是我的代码,以帮助演示我看到的内容:
# score the model using cross_val_score
rf = RandomForestClassifier(n_estimators=150,
min_samples_leaf=4,
min_samples_split=3,
n_jobs=-1)
scores = cross_val_score(rf, X, y, cv=3, scoring='roc_auc')
print scores
array([ 0.9649023 , 0.96242235, 0.9503313 ])
# do a train_test_split, fit the model, and score with roc_auc_score
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33)
rf.fit(X_train, y_train)
print roc_auc_score(y_test, rf.predict(X_test))
0.84634039111363313 # quite a bit different than the scores above!
我觉得我在这里缺少了一些非常简单的东西——很可能是我在实现/解释其中一个评分指标时犯了错误。
有人能否解释一下这两个评分指标之间差异的原因?