Reputation: 61
I have to implement a loss function using mean absolute error without calling the built-in function. Is the code below correct? Because my loss value goes from 28.xx to 0.00028 quickly.
Meanwhile, other loss function like RMSE has a more standard loss curve
loss = tf.reduce_sum(tf.abs(y_pred - Y) / nFeatures)
Upvotes: 0
Views: 2951
Reputation: 1966
You can implement your own lost function base on MAE formula:
import tensorflow as tf
MAE = tf.reduce_mean(tf.abs(y_true - y_pred))
Also you can check customized loss function in this answer
or
import numpy as np
MAE = np.average(np.abs(y_true - y_pred), weights=sample_weight, axis=0)
or
from tensorflow.python.ops import math_ops
MAE = math_ops.abs(y_true - y_pred)
Upvotes: 2