2

EDIT: It was actually a divide-by-zero error. :(

I created a metric function in Keras to calculate the average fractional error; that is, for each actual/predicted pair I calculate abs(actual - predicted)/actual, then find the mean across all the data. The code is below.

def avg_frac_error(y_actual, y_pred):
    return K.mean(K.abs(y_actual - y_pred)/ y_actual)

When applying the metric on a small dataset (say 6,000 scalar values), the result is produced accurately. When calculating it on a larger one (10,000 values) the result is inf. I suspect that it's failing at the K.mean, as the same occurs when I try to calculate the mean manually. I have tested both tensorflow and theano backends.

What workaround could I do to calculate the mean?

thornate
  • 4,902
  • 9
  • 39
  • 43

0 Answers0