I have a binary classification problem.
I am using the log_loss from tensorflow.losses.log_loss
.
To check, I use sklearn.metrics.log_loss
. Most of the times, the two functions give the same result (only difference in dtype). In some instance, the sklearn
function returns NaN
while tf.losses.log_loss
returns a correct value.
data is here: https://pastebin.com/BvDgDnVT
code:
import sklearn.metrics
import tensorflow as tf
y_true = [... see pastebin link]
y_pred = [... see pastebin link]
loss_sk = sklearn.metrics.log_loss(y_true, y_pred, labels=[0, 1]) # -> returns NaN
with tf.Session() as sess:
loss_tf = tf.losses.log_loss(y_true, y_pred).eval(session=sess) # -> returns 0.0549
There seems to be some log(0)
happening, but why does tensorflow not have this problem?