Skip to content Skip to sidebar Skip to footer

Tensorflow Cost Value Return Nan

I am making a simple Logistic Regression Model using Tensorflow. But the cost value is always returning nan. My data sets are divided into x_data and y_data. x_data is a coordinate

Solution 1:

When your hypothesis is equal to 1, your second part of the loss becomes Y * log(0), hence the nan output. I suggest you to add a small constant inside the logarithm and it should work. Try this

cost = -tf.reduce_mean(Y*(tf.log(hypothesis+1e-4))+(1-Y)*(tf.log(1-hypothesis+1e-4)))

Post a Comment for "Tensorflow Cost Value Return Nan"