I have written a sequential classifier script using Keras, Tensorflow. Its a binary image classifier that predicts the class, given the directory path of a sample image.

I want to implement a probability feature in my script, where including the class, the correctness probability of my classifier's prediction is given too. for eg:


img = image.load_img('dataset/test/sample/fff.jpeg', target_size = (img_width, img_height))
img = image.img_to_array(img)
img = np.expand_dims(img, axis = 0)

prediction = model.predict(img)

OUTPUT (something like)

Prediction: 80% seems like it being Class A

In other words, I want to display my classifiers accuracy for that particular image.

P.S I am sorry if the question seems a little abrupt. I have tried asking it elsewhere too but either It gets closed due to lack of information, Or its misunderstood as "Classifier training accuracy" by google as its hard for me to frame it.


Accuracy is a statistic that you can compute on a dataset if you know the true labels. For a single image, the accuracy is either 0% or 100% based on if you get it right or wrong.

In the newer versions of Keras, the predict method returns the probabilities of the classes, what you want to print is (if I guess correctly), the probability score for the best scoring class.

Not that this is not an unbiased estimate of the class probability. Neural classifiers tend to very confident even if their prediction is incorrect.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.