2

I use a Keras EfficientNetB7 and transfer learning to solve a binary classification problem. I use tf.keras.layers.Dense(1, activation="sigmoid")(x) for my final layer.

My labels are encoded as the following for the model.fit():

[[1.]
 [1.]
 [0.]
 [1.]
  ...
 [1.]
 [1.]
 [0.]]

My question is about the output of the model.predict(). For example, if the output is [[0.09122807]], does this mean that the prediction is class 1. or 0.?

Initially, I assumed it would have been class 0. but my model predicts the opposite of this assumption. In some stackoverflow posts, I saw that the output should be used 1 - p where p is the probability of class 1.

There is conflicting information on the net; hence, wanted to ask your guidance.

nbro
  • 42,615
  • 12
  • 119
  • 217
Doug
  • 125
  • 3

1 Answers1

3

If you are using binary cross-entropy as loss function, the output of Sigmoid functions represent the probability of $\mathbb{P}[y=1]$. Hence, it means that $\mathbb{P}[y=0] = 1 - \mathbb{P}[y=1]$. Therefore, when the output is $0.09$, it means that the prediction is $y=0$ as it is more probable ($1-0.09 = 0.91$).

OmG
  • 1,866
  • 12
  • 19