已知一个分类器在测试集上的混淆矩阵如下表所示,该分类器对各个类别的召回率为:
M = [[69, 3, 13, 11, 4],
[14, 70, 3, 7,6],
[3,3,80, 9, 5],
[3,6,9,76,4],
[8, 11, 4, 23, 54]]n = len(M)
for i in range(len(M[0])):
rowsum, colsum = sum(M[i]), sum(M[r][i] for r in range(n))
try:
print('precision: %s' % (M[i][i]/float(colsum)), 'recall: %s' % (M[i][i]/float(rowsum)))
except ZeroDivisionError:
print('precision: %s' % 0, 'recall: %s' %0)
【笔试-混淆矩阵-召回率】结果为:
precision: 0.711340206185567 recall: 0.69
precision: 0.7526881720430108 recall: 0.7
precision: 0.7339449541284404 recall: 0.8
precision: 0.6031746031746031 recall: 0.7755102040816326
precision: 0.7397260273972602 recall: 0.54