我尝试计算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: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples."
f1_score
也无法正常工作。 - E.Z