【发布时间】:2020-11-21 07:22:43
【问题描述】:
我有四个类(标记为 0、1、2、3)的问题。我有一个训练和评估的模型。我什至有一个混淆矩阵。但是我想看看被错误分类的图像样本,主要是FP和FN,这样我就知道哪个样本模型在分类上有问题。
任何建议都会有很大帮助。
【问题讨论】:
标签: python tensorflow keras deep-learning conv-neural-network
我有四个类(标记为 0、1、2、3)的问题。我有一个训练和评估的模型。我什至有一个混淆矩阵。但是我想看看被错误分类的图像样本,主要是FP和FN,这样我就知道哪个样本模型在分类上有问题。
任何建议都会有很大帮助。
【问题讨论】:
标签: python tensorflow keras deep-learning conv-neural-network
In this stackoverflow answer 我展示了一种处理二进制大小写的方法。我对您的问题的想法是找到每个班级各自的 FP 和 FN。所以我想做的是
代码:
import numpy as np
real = np.array([1,1,1,2,2,2,0,0,0,3,3,3])
predicted = np.array([1,1,0,2,2,1,0,0,2,3,3,1])
classes = np.array([0,1,2,3])
def get_dummy_values(a: np.ndarray, cls: int):
temp = a.copy()
mask = (temp == cls)
temp[mask] = 1
temp[~mask] = 0
return temp
diffs = np.empty((len(classes), len(real)), dtype=np.int)
for i, cls in enumerate(classes):
dum_real = get_dummy_values(real, cls)
dum_pred = get_dummy_values(predicted, cls)
diffs[i] = dum_real - dum_pred
print(f'{f" Diffs ":=^40}')
print(diffs, end='\n\n')
for diff, cls in zip(diffs, classes):
print(f'{f" For class {cls} ":=^40}')
print('False positives: ', np.where(diff == -1)[0])
print('False negatives: ', np.where(diff == 1)[0], end='\n\n')
输出:
================ Diffs =================
[[ 0 0 -1 0 0 0 0 0 1 0 0 0]
[ 0 0 1 0 0 -1 0 0 0 0 0 -1]
[ 0 0 0 0 0 1 0 0 -1 0 0 0]
[ 0 0 0 0 0 0 0 0 0 0 0 1]]
============= For class 0 ==============
False positives: [2]
False negatives: [8]
============= For class 1 ==============
False positives: [ 5 11]
False negatives: [2]
============= For class 2 ==============
False positives: [8]
False negatives: [5]
============= For class 3 ==============
False positives: []
False negatives: [11]
注意:假设您的模型预测“大部分正确”,则 diffs 矩阵非常稀疏,因此最好为该任务使用内存效率更高的数据结构(以防您有很多标签)。
【讨论】: