from sklearn.metrics import precision_score
precision_score(expected, predicted)
期望为array([ 4., 3.])
,预测为array([ 2., 4.])
我得到了报酬。error: *** ValueError: pos_label=1 is not a valid label: array([ 2., 3., 4.])
如何解决这个问题?
多类标签需要average
参数
否则,您需要将pos_label
设置为两个数组中的类标签之一,即2,3或4:
>>> # score for all classes
>>> precision_score(expected, predicted, average=None)
array([ 0., 0., 0.])
>>> # score for each class
>>> precision_score(expected, predicted, pos_label=2)
0.0
>>> precision_score(expected, predicted, pos_label=3)
0.0
>>> precision_score(expected, predicted, pos_label=4)
0.0
参考:sklearn.metrics.precision_score