Skip to content Skip to sidebar Skip to footer

Keras - Precision And Recall Is Greater Than 1 (multi Classification)

I am working on a multi classification problem using CNN's in keras. My precision and recall score is always over 1 which does not make any sense at all. Attached below is my code,

Solution 1:

I was able to figure this out. The above code works perfectly once you one-hot encode all the categorical labels. Also, make sure you do NOT have sparse_categorical_crossentropy as your loss function, and instead just use categorical_crossentropy.

If you wish to convert your categorical values to one-hot encoded values in Keras, you can just use this code:

from keras.utils importto_categoricaly_train= to_categorical(y_train)

The reason you have to do the above is noted in Keras documentation:

"when using the categorical_crossentropy loss, your targets should be in categorical format (e.g. if you have 10 classes, the target for each sample should be a 10-dimensional vector that is all-zeros except for a 1 at the index corresponding to the class of the sample). In order to convert integer targets into categorical targets, you can use the Keras utility to_categorical"

Post a Comment for "Keras - Precision And Recall Is Greater Than 1 (multi Classification)"