1

I'm using keras with last layer as softmax which returns a probability (0-1.0) float values. Suppose I have 4 classes, how can I get the index of the class that has the highest probability? Is there a keras, numpy or scikit-learn function to do this?

pred = model.predict(....)
# pred = [[0.9, 0.0, 0.0, 0.1],   --------> [0, 1, 1]
#         [0.1, 0.8, 0.1, 0.0],   change to
#         [0.1, 0.8, 0.1, 0.0]]

The reason I want to change from array of 0-1 float to integer is because I want to use scikit-learn's confusion matrix to visualise the accuracy and it only accepts integer labels.

matchifang
  • 5,190
  • 12
  • 47
  • 76

0 Answers0