My TensorFlow model has the following structure. It aims to solve a binary classification problem where the labels are either 0 or 1. The output layer uses a sigmoid activation function with 1 output.
model = keras.Sequential([
layers.Dense(10, activation='relu', input_shape=[len(train_dataset.keys())]),
layers.Dense(1, activation='sigmoid')
])
optimizer = 'adam'
model.compile(loss='binary_crossentropy',
optimizer=optimizer,
metrics=[tf.keras.metrics.Precision(), tf.keras.metrics.Recall(), tf.keras.metrics.Accuracy()])
The output given is an array of dtype=float32 numbers that lie between 0 and 1.
array([[9.5879245e-01],
[3.6847022e-01],
[3.4174323e-04],
...,
[2.6283860e-03],
[3.2045375e-04],
[1.0798702e-03]], dtype=float32)
The Tensorflow tutorials state that "Using the sigmoid activation function, this value is a float between 0 and 1 and represents a probability, or confidence level". https://www.tensorflow.org/tutorials/keras/text_classification
My question is:
Do I interpret the float values from output as:
- "How likely it belongs to the first class label - in this case class 0 is my first class label?" e.g.
model.predict()
yields0.99998
and therefore has a 99% chance of belonging to my first class label (class 0) and 1% belonging to the other class (class 1).
or
- "The closer the output from
model.predict()
is to0.0
the more likely it is class 0 and the closer the output is to1.0
the more likely it is class 1"