当您使用cross_val_score方法时,您可以指定您可以在每个折叠上计算哪些刻度:
from sklearn.metrics import make_scorer, accuracy_score, precision_score, recall_score, f1_score
scoring = {'accuracy' : make_scorer(accuracy_score),
'precision' : make_scorer(precision_score),
'recall' : make_scorer(recall_score),
'f1_score' : make_scorer(f1_score)}
kfold = model_selection.KFold(n_splits=10, random_state=42)
model=RandomForestClassifier(n_estimators=50)
results = model_selection.cross_val_score(estimator=model,
X=features,
y=labels,
cv=kfold,
scoring=scoring)
交叉验证后,您将获得带有键的结果字典:’准确性’,’精确’,’召回’,’f1_score’,它在特定指标的每个折叠上存储指标值.对于每个度量,您可以使用np.mean(结果[值])和np.std(结果[值])计算平均值和标准值,其中value – 您指定的度量标准名称之一.