繁体   English   中英

从混淆矩阵计算真实正值以进行多类分类

[英]Computing true positive value from confusion matrix for multi class classification

对于多类分类问题,我需要从我的混淆矩阵中计算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'而将类加载到一个热编码值中,因此我正在使用这种方法来计算传导矩阵也是正确的。

TP对角线元素(302,56,69,34)

FP-[23 102 15],[34 34 340],[34 32 54],[231 89 32]

TN-无值

FN-无值

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM