Skip to content Skip to sidebar Skip to footer

Get List Of True Positives, False Positives, False Negatives And True Negatives With Tensorflow

Here is my work : I have annotated images of 'Living' cells (circa 8.000) and images of 'Dead' cells (circa 2.000) (+ 800 and 200 for testing set) I am using CNN (with tensorflow

Solution 1:

For the case of binary classification you can take difference between the vector of true labels and the predicted labels. The difference vector will contain zeros where it classified correctly, -1 for false positives, 1 for false negatives. You can then for example use np.where to find the indices of false positives and whatnot.

To get the indices of false positives and false negatives etc you can simply do:

import numpy as np 

real = np.array([1,0,0,1,1,1,1,1])
predicted = np.array([1,1,0,0,1,1,0,1])

diff = real-predicted
print('diff: ',diff)

# Correct is 0 # FP is -1 # FN is 1print('Correctly classified: ', np.where(diff == 0)[0])
print('Incorrectly classified: ', np.where(diff != 0)[0])
print('False positives: ', np.where(diff == -1)[0])
print('False negatives: ', np.where(diff == 1)[0])

output:

diff:  [ 0-1010010]
Correctly classified:  [02457]
Incorrectly classified:  [136]
False positives:  [1]
False negatives:  [36]

Post a Comment for "Get List Of True Positives, False Positives, False Negatives And True Negatives With Tensorflow"