Reputation: 2296
I'm trying to implement MAPE(Mean Absolute Percentage Error) in tensorflow. I'm taking output from the RNN.
Here is my code :
loss = tf.reduce_mean(tf.abs(tf.divide(tf.subtract(outputs,y),y)))
But on running the session I'm getting MAPE as NaN. What am I doing wrong ?
Upvotes: 1
Views: 2285
Reputation: 1842
I strongly suspect you are getting NaN because y is zero. To get around this you can add a very small epsilon value to y denominator to ensure it's never zero, but small enough not to skew your calculations:
loss = tf.reduce_mean(tf.abs(tf.divide(tf.subtract(outputs,y),(y + 1e-10))))
Upvotes: 3
Reputation: 1
You get nan because y includes a zero value. Therefore it is impossible tensorflow to produce the division as a result it outputs inf.
Upvotes: 0