求视频二分类的f1score,知pred和label的tensor求f1score
1条回答 默认 最新
- 稀饭稠粥 2023-03-10 19:31关注
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.6666666666666666pred和label的值分别为:
pred: [0, 1, 1, 0]
label: [1, 1, 0, 0]
f1 score的计算公式为:
f1 = 2 * (precision * recall) / (precision + recall)其中,precision和recall的计算公式分别为:
precision = true_positive / (true_positive + false_positive)
recall = true_positive / (true_positive + false_negative)true_positive表示预测为正样本且真实为正样本的数量,false_positive表示预测为正样本但真实为负样本的数量,false_negative表示预测为负样本但真实为正样本的数量。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用