Mean Absolute Error -
it is straight forward
import numpy as np
import tensorflow as tf
y_true = np.float32([1,2] )
y_pred = np.float32([2,2] )
#loss = mean(abs(y_true - y_pred))
#np.abs will return the absolute values , nps.abs[-1] will return 1
loss_mae = tf.keras.losses.mean_absolute_error(y_true, y_pred)
print(loss_mae.numpy())
print(np.mean(np.abs(y_true - y_pred)))
print and verify
0.5 0.5or u can run the code in colab using the link
reference -
https://www.tensorflow.org/api_docs/python/tf/keras/metrics/mean_absolute_error
Comments
Post a Comment