针对不同指标的交叉验证 - Sklearn

时间:2018-03-12 17:12:25

标签: python python-3.x scikit-learn cross-validation

当我使用Python的Sklearn进行交叉验证并获取不同指标(准确度,精度等)的得分时,如下所示:

result_accuracy = cross_val_score(classifier, X_train, y_train, scoring='accuracy', cv=10)
result_precision = cross_val_score(classifier, X_train, y_train, scoring='precision', cv=10)
result_recall = cross_val_score(classifier, X_train, y_train, scoring='recall', cv=10)
result_f1 = cross_val_score(classifier, X_train, y_train, scoring='f1', cv=10)

针对不同指标的cross_val_score()函数的每次执行是否与训练数据的10倍相同?如果没有,我是否需要首先使用KFold制作一般的10倍,如下所示:

seed = 7
kf = KFold(n_splits=10, random_state=seed)

result_accuracy = cross_val_score(classifier, X_train, y_train, scoring='accuracy', cv=kf)
result_precision = cross_val_score(classifier, X_train, y_train, scoring='precision', cv=kf)
result_recall = cross_val_score(classifier, X_train, y_train, scoring='recall', cv=kf)
result_f1 = cross_val_score(classifier, X_train, y_train, scoring='f1', cv=kf)

1 个答案:

答案 0 :(得分:1)

在cross_val_score中使用random_state param每次都设置相同的分割。

result_accuracy = cross_val_score(classifier, X_train, y_train, scoring='accuracy', cv=10, random_state=42)