为什么precision_recall_fscore_support返回2个值?

问题描述

我是第一次使用precision_recall_fscore_support

precision,recall,fscore,support = score(y_test,y_pred)


print('precision: {}'.format(precision))
print('recall: {}'.format(recall))
print('fscore: {}'.format(fscore))
print('support: {}'.format(support))

但是我每个都有2个值

precision: [0.67420814 0.67032967]
recall: [0.62343096 0.71764706]
fscore: [0.64782609 0.69318182]
support: [239 255]

为什么每个评估都有2个值?

以及如何获得标准的precision / recall / f1score

解决方法

我不确定您在说什么分数,我相信它是sklearn库中的.score(),如果是这样,那么下面就是答案。

Parameters
X : array-like,shape = (n_samples,n_features)
Test samples.
y : array-like,shape = (n_samples) or (n_samples,n_outputs)
True values for X.
sample_weight : array-like,shape = [n_samples],optional
Sample weights.
**Returns**
score : float
either accuracy or R^2 of self.predict(X) wrt. y.

在我看来,您认为o / p中有2个类,因此它返回2个值。 e.x:class1精度为0.67420814,class2为0.67032967

以下链接可能会为您提供帮助,https://www.kite.com/python/docs/sklearn.kernel_ridge.KernelRidge.score

我建议您使用category_report(https://scikit-learn.org/stable/modules/generated/sklearn.metrics.classification_report.html)库,这样可以最大程度地减少工作量。