ggsDing / SCanNet

38 stars 1 forks source link

Eval中关于TN FP FN TP的计算是不是有误 #12

Closed Chelsea0216 closed 6 months ago

Chelsea0216 commented 6 months ago
hist_fg = hist[1:, 1:]
c2hist = np.zeros((2, 2))
c2hist[0][0] = hist[0][0]                   #TN 真实负样本
c2hist[0][1] = hist.sum(1)[0] - hist[0][0]  #FP 负样本被错误预测为正样本
c2hist[1][0] = hist.sum(0)[0] - hist[0][0]  #FN 正样本错误被预测为负样本
c2hist[1][1] = hist_fg.sum()                #TP 真实正样本
print('bn_hist: TP %d, FN %d, FP %d, TN %d'%(c2hist[1][1], c2hist[1][0], c2hist[0][1], c2hist[0][0]))

这是多类而不是二类别的混淆矩阵,TP应该是对角线上所有元素之和而不是hist[1:, 1:]? 另外,FP和FN是不是弄反了,同样也只计算了二类而不是多类?

YuhangZh commented 6 months ago

So the correct algorithm should be tp = np.diag(hist).sum(). tp=hist[1:, 1:].sum() is to compute the sum of the elements of the remaining portion of the confusion matrix after removing the first row and column of the confusion matrix, which is how tp is computed in binary classification.

ggsDing commented 6 months ago
hist_fg = hist[1:, 1:]
c2hist = np.zeros((2, 2))
c2hist[0][0] = hist[0][0]                   #TN 真实负样本
c2hist[0][1] = hist.sum(1)[0] - hist[0][0]  #FP 负样本被错误预测为正样本
c2hist[1][0] = hist.sum(0)[0] - hist[0][0]  #FN 正样本错误被预测为负样本
c2hist[1][1] = hist_fg.sum()                #TP 真实正样本
print('bn_hist: TP %d, FN %d, FP %d, TN %d'%(c2hist[1][1], c2hist[1][0], c2hist[0][1], c2hist[0][0]))

这是多类而不是二类别的混淆矩阵,TP应该是对角线上所有元素之和而不是hist[1:, 1:]? 另外,FP和FN是不是弄反了,同样也只计算了二类而不是多类?

这部分代码来自竞赛,应当没什么问题,不过我没有细看。 根据标注规则,0表示未变化,1: 表示各类别。二分类和多分类的tp应该是分开计算的。请参考核实下。