As an input a have a float 1.0 or 0.0. When I try to predict with my model and the sparse_categorical_crossentropy
loss I get something like:
[[0.4846592 0.5153408]]
.
How do I know what category it predicts?
As an input a have a float 1.0 or 0.0. When I try to predict with my model and the sparse_categorical_crossentropy
loss I get something like:
[[0.4846592 0.5153408]]
.
How do I know what category it predicts?
These numbers you see are the probability of each class for the given input sample. For example, [[0.4846592 0.5153408]]
means that the given sample belongs to class 0 with probability of around 0.48 and it belongs to class 1 with probability of around 0.51. So you want to take the class with the highest probability and therefore you can use np.argmax
to find which index (i.e. 0 or 1) is the maximum one:
import numpy as np
pred_class = np.argmax(probs, axis=-1)
Further, this has nothing to do with the loss function of the model. These probabilities are given by the last layer in your model which is very likely that it uses softmax
as the activation function to normalize the output as a probability distribution.