【发布时间】:2018-03-25 18:21:41
【问题描述】:
我尝试计算 f1_score,但在使用 sklearn f1_score 方法时会收到一些警告。
我有一个多标签 5 类预测问题。
import numpy as np
from sklearn.metrics import f1_score
y_true = np.zeros((1,5))
y_true[0,0] = 1 # => label = [[1, 0, 0, 0, 0]]
y_pred = np.zeros((1,5))
y_pred[:] = 1 # => prediction = [[1, 1, 1, 1, 1]]
result_1 = f1_score(y_true=y_true, y_pred=y_pred, labels=None, average="weighted")
print(result_1) # prints 1.0
result_2 = f1_score(y_true=y_ture, y_pred=y_pred, labels=None, average="weighted")
print(result_2) # prints: (1.0, 1.0, 1.0, None) for precision/recall/fbeta_score/support
当我使用 average="samples" 而不是 "weighted" 时,我得到 (0.1, 1.0, 0.1818..., None)。 "weighted" 选项对于多标签问题是否无用,或者我如何正确使用 f1_score 方法?
我在使用 average="weighted" 时也会收到警告:
“UndefinedMetricWarning:召回率和 F 分数定义不明确,在没有真实样本的标签中设置为 0.0。”
【问题讨论】:
标签: scikit-learn metrics multilabel-classification precision-recall