UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted sa

from sklearn import metrics

y_true = [0, 1, 2, 0, 1, 2]
y_pred = [0, 2, 1, 0, 0, 1]

y_true_1 = [0, 1, 2, 0, 1, 2]
y_pred_1 = [0, 2, 3, 0, 0, 1]

y_true_2 = [0, 1, 2, 0, 1, 2]
y_pred_2 = [0, 1, 1, 0, 0, 1]


print metrics.precision_score(y_true, y_pred, average='macro')
# print metrics.precision_score(y_true_1, y_pred_1, average='macro')
# print metrics.precision_score(y_true_2, y_pred_2, average='macro')

打印第一句结果为:

0.222222222222

第二句结果为:

0.166666666667

第三句结果为:

0.333333333333
C:\Python27\lib\site-packages\sklearn\metrics\classification.py:1113: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples.
  'precision', 'predicted', average, warn_for)

当预测的值中不包含有实际值时会报错。
请参考:sklearn.metrics.precision_score

你可能感兴趣的:(机器学习,Python)