I'm using MNIST example with 60000 training image and 10000 testing image. How do I find which of the 10000 testing image that has an incorrect classification/prediction?
Asked
Active
Viewed 1.3k times
2 Answers
24
Simply use model.predict_classes()
and compare the output with true labes. i.e:
incorrects = np.nonzero(model.predict_class(X_test).reshape((-1,)) != y_test)
to get indices of incorrect predictions

S.Mohsen sh
- 2,028
- 3
- 21
- 32
-
How can I generate a sub-folder with the wrong classified cases inside each class folder?? – Joaquín Fernández Feb 25 '18 at 20:02
-
if x, y are numpy check out the [answer](https://stackoverflow.com/a/28440249/13717851) – Sayan Dey Aug 23 '20 at 13:12
2
Editing as was not clear earlier
To identify the image files that are wrongly classified, you can use:
fnames = test_generator.filenames ## fnames is all the filenames/samples used in testing
errors = np.where(y_pred != test_generator.classes)[0] ## misclassifications done on the test data where y_pred is the predicted values
for i in errors:
print(fnames[i])

SnigA
- 147
- 10
-
-
How can I print the actual class and predicted class as well along with the image name? – Hardik Raval Apr 23 '21 at 06:38
-
when I print fnames, it printed same file name multiple times. Any update? – Hello-experts Mar 08 '22 at 07:55