from sklearn.metrics import precision_score

precision_score(expected, predicted)


哪里是array([ 4., 3.])

并且预测为array([ 2., 4.])

我明白了。错误:*** 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

关于python - 使用scikit-learn计算精度时出现ValueError,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39820260/

10-12 16:59