【发布时间】:2019-07-07 19:30:08
【问题描述】:
对于多类分类问题,我需要从我的混淆矩阵中计算 TP、FP、TN 和 FN 值。
因为我需要获得敏感性和特异性。
这是我的混淆矩阵的样子,我总共有 4 个类:
[[302 23 102 15]
[34 56 34 340]
[34 32 69 54]
[231 89 32 34]]
这是我的部分代码
#loading data using generator with class mode = categorical
test_datagen = ImageDataGenerator(rescale = 1./255)
test_set = test_datagen.flow_from_directory('animals/valid/',
target_size=(150,150),class_mode='categorical',batch_size=32)
#compile the model with categorical cross entropy
model.compile(loss='categorical_crossentropy',optimizer=Adam(lr=0.00001),metrics=['accuracy'])
#calculate confusion matrix
test_im, test_lbl = next(test_set)
predections = model.predict(test_im)
predections = np.argmax(predections, axis = 1)
test_lbl = np.argmax(test_lbl, axis = 1)
conf_mat = confusion_matrix(all_labels, all_predications)
由于在图像生成器中使用了 class_mode='categorical',因此我在计算传导矩阵时使用这种方法也是正确的。
【问题讨论】:
标签: python keras deep-learning confusion-matrix