【发布时间】:2018-08-05 10:13:24
【问题描述】:
当我使用以下代码为一类计算precision_recall_fscore_support 时(仅1s)
import numpy as np
from sklearn.metrics import precision_recall_fscore_support
#make arrays
ytrue = np.array(['1', '1', '1', '1', '1','1','1','1'])
ypred = np.array(['0', '0', '0', '1', '1','1','1','1'])
#keep only 1
y_true, y_pred = zip(*[[ytrue[i], ypred[i]] for i in range(len(ytrue)) if ytrue[i]=="1"])
#get scores
precision_recall_fscore_support(y_true, y_pred, average='weighted')
我收到以下警告:
UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples.
'recall', 'true', average, warn_for)
和输出:
(1.0, 0.625, 0.76923076923076927, None)
我在 SO UndefinedMetricWarning: F-score is ill-defined and being set to 0.0 in labels with no predicted samples 上发现了以下具有类似警告的内容,但我认为它不适用于我的问题。
问题:我的输出结果是否有效,或者我应该关注警告消息吗?如果是这样,我的代码有什么问题以及如何解决?
【问题讨论】:
-
阅读这些指标是如何定义的,就会清楚为什么不能用当前数据计算它们。这就像试图计算仅男性样本中女性吸烟者的比例。没有意义。
-
我尝试了下面的代码。但是,它被否决了,但我不知道为什么。
标签: python machine-learning scikit-learn precision-recall