我对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!
Run Code Online (Sandbox Code Playgroud)
我觉得我在这里错过了一些非常简单的事情 - 很可能是我如何实施/解释其中一个评分指标的错误.
任何人都可以解释两个得分指标之间差异的原因吗?
python machine-learning random-forest scikit-learn cross-validation
sklearn roc_curve docstring声明:
"y_score:array,shape = [n_samples]目标分数,可以是正类的概率估计,置信度值或二元决策."
在什么情况下将y_score设置为二进制向量("二元决策")是有意义的?这不会导致一个ROC曲线上有一个点,哪一种无视这一点?