这是我用Python编写的代码,用于计算K-Fold交叉验证的准确度、精确度、召回率、f1分数。在我的代码中,我总结了我的每一个准确率、召回率等。然后我将其除以n_folds。但我不知道我的公式计算这些分数是否准确。我的意思是代码给我的值是准确的。实际上我没有任何好的文档来计算这些分数。
a=0
p=0
r=0
f=0
for fold in range(0, n_folds):
# splitting the dataset
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size =int(len(y)/n_folds))
clf.fit(X_train, y_train)
x_test_prediction = clf.predict(X_test)
a=a+accuracy_score(x_test_prediction, y_test)
p=p+precision_score(x_test_prediction, y_test)
r=r+recall_score(x_test_prediction, y_test)
f=f+f1_score(x_test_prediction, y_test)
accuracy_score=a
precision_score=p
recall_score=r
f1_score=f
print("accuracy score :",(accuracy_score)/n_folds)
print("precision score :",precision_score/n_folds)
print("recall score :",recall_score/n_folds)
print("f1 score :",f1_score/n_folds)
请查看 sklearn.metrics 分类指标。