Tensorflow predict the class of output Tensorflow predict the class of output python-3.x python-3.x

Tensorflow predict the class of output


You are trying to map the predicted class probabilities back to class labels. Each row in the list of output predictions contains the three predicted class probabilities. Use np.argmax to obtain the one with the highest predicted probability in order to map to the predicted class label:

import numpy as nppredictions = [[0.3112209,  0.3690182,  0.31357136], [0.31085992, 0.36959863, 0.31448898], [0.31073445, 0.3703295, 0.31469804], [0.31177694, 0.37011752, 0.3145326 ], [0.31220382, 0.3692756, 0.31515726], [0.31232828, 0.36947766, 0.3149037 ], [0.31190437, 0.36756667, 0.31323162], [0.31339088, 0.36542615, 0.310322  ], [0.31598282, 0.36328828, 0.30711085]] np.argmax(predictions, axis=1) 

Gives:

array([1, 1, 1, 1, 1, 1, 1, 1, 1])

In this case, class 1 is predicted 9 times.

As noted in the comments: this is exactly what Keras does under the hood, as you'll see in the source code.