1
$\begingroup$

I am doing a image classification with CNN using Keras. The training process was so far so good. But when it comes to the prediction, I couldn't figure out to extract correct prediction results out of numpy array from predict(x). It is binary classification task but I used softmax layer at the end purposefully. The original labels should look like this:

[0 1 0 1 1 1 0 0]

But I have this from predict:

[[ 1.00000000e+00 0.00000000e+00]
[ 1.00000000e+00 1.13929331e-32]
[ 1.00000000e+00 0.00000000e+00]
[ 1.00000000e+00 1.51848069e-28]
[ 1.00000000e+00 3.70465143e-38]
[ 1.00000000e+00 5.44319748e-37]
[ 1.00000000e+00 0.00000000e+00]
[ 1.00000000e+00 0.00000000e+00]]

Apparently, there is a pattern in the output with ones and super small numbers that resembles the real labels although these small numbers should be greater than the ones before them. How can I transform it to look like the original one.

$\endgroup$

closed as off-topic by Michael Chernick, kjetil b halvorsen, StasK, Peter Flom - Reinstate Monica Sep 20 '17 at 11:45

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – Michael Chernick, kjetil b halvorsen, Peter Flom - Reinstate Monica
If this question can be reworded to fit the rules in the help center, please edit the question.

1
$\begingroup$

If you are doing binary classification, each row should give you probability on two classes. In other words, each row should sum up to 1.0.

To get the prediction label, for each row, find the max probability and return the index. Can be done using numpy.argmax

https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.argmax.html

$\endgroup$
  • $\begingroup$ Yes, if I do numpy.argmax(output, axis=1) it gives [0, 0, 0, 0, 0, 0, 0, 0], because apparently in each row of prediction matrix value of 0th index is always greater the second one and always equals to 1. I don't know why but there is a pattern in output matrix which resembles the original answer. $\endgroup$ – Odgiiv Sep 19 '17 at 16:08
  • $\begingroup$ ok, I see your question, are are asking the difference between 0 and a super small number, like $1.1\times 10^{-32}$. With this detail, it is hard to answer why this happen for me. $\endgroup$ – Haitao Du Sep 19 '17 at 16:48

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