I need to calculate TP, FP, TN and FN values from my confusion matrix for a multi class classification problem.
As I need to get sensitivity and specificity.
Here is what my confusion matrix looks like, I have 4 classes total:
[[302 23 102 15]
[34 56 34 340]
[34 32 69 54]
[231 89 32 34]]
Here are parts of my code
#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)
Also is it correct that I am using this approach in calculating conduction matrix given that classes are loaded in one hot encoding values because of using class_mode='categorical'in the image generator.