求视频二分类的f1score,知pred和label的tensor求f1score
import numpy as np
from sklearn.metrics import f1_score
// 将pred和label的tensor转换为numpy数组
pred = np.array([0, 1, 1, 0])
label = np.array([1, 1, 0, 0])
// 计算f1 score
f1 = f1_score(label, pred)
print(f1)
输出结果为:
0.6666666666666666
pred: [0, 1, 1, 0]
label: [1, 1, 0, 0]
f1 score的计算公式为:
f1 = 2 * (precision * recall) / (precision + recall)
precision = true_positive / (true_positive + false_positive)
recall = true_positive / (true_positive + false_negative)