5

Looking at tensorflow docs for MAE, I saw that tf.metrics.mean_absolute_error will return:

  • mean_absolute_error: A Tensor representing the current mean, the value of total divided by count.
  • update_op: An operation that increments the total and count variables appropriately and whose value matches mean_absolute_error.

How to implement this for evaluation purpose? As stated here:

mean_absolute_error is intended for evaluation and so it doesn't have a gradient. mean_absolute_error also returns an update op (which are you ignoring in the code above) that must be used to update the mean, so the concept of a gradient for this function doesn't really make sense. The update op for tf.metrics.mean_absolute_error(pred, y) must be called before the mean can be obtained.

I don't know how to deal with returned value from mean_absolute_error function. Can someone write a simple example with this function? Thanks a lot.

1 Answer 1

2

It sounds like you are not sure what the returned tensors/operations mean and how to use them. Here is a nice article explaining the how as well as the why: http://ronny.rest/blog/post_2017_09_11_tf_metrics/

For a simple self-contained example usage you can see the tests. For example: https://github.com/tensorflow/tensorflow/blob/cda36b817e9998906da37ec87c525f1b278c71a7/tensorflow/python/kernel_tests/metrics_test.py#L2816

4
  • The article is useful enough for me. Detailed explained why and how we could use tf.metrics. Although it talk about accuracy but the same logic for mean absolute error.
    – truongnm
    Commented Apr 14, 2018 at 13:38
  • Would you mind recap about the above articles, incase the article goes 404. @iga
    – truongnm
    Commented Apr 14, 2018 at 13:39
  • article no longer available. @truongnm by any chance do you have any leads?
    – momo
    Commented Dec 18, 2019 at 7:32
  • 1
    Sorry for slow response! You can use google webcache incase the link die. Google save the snapshot of every website. webcache.googleusercontent.com/search?q=cache:http://ronny.rest/… Anyway, I found the same article in steemit, the author post there too. steemit.com/machine-learning/@ronny.rest/… @momo
    – truongnm
    Commented Dec 18, 2019 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.