loss_function_mae


Loss function: Mean Absolute Error.

mae = loss_function_mae(y_true, y_pred)

Input variables

Name Description Type
y_true True values List
y_pred Predicted values List

Output variables

Name Description Type
mae Mean Absolute Error Float

Problem

\[f(\mathbf{y}_{\text{true}}, \mathbf{y}_{\text{pred}}) = \frac{1}{n} \cdot \sum_{i=1}^{n} |y_{\text{true},i} - y_{\text{pred},i}|\]

(1)

\(n\) is the number of samples.

Example 1

Considering the true values \(\mathbf{y}_{\text{true}} = [1.0, 2.0, 3.0, 4.0, 5.0]\) and predicted values \(\mathbf{y}_{\text{pred}} = [1.2, 2.3, 2.9, 4.2, 5.3]\), what is the resulting Mean Absolute Error (MAE)?

# Data
y_true_example = [1.0, 2.0, 3.0, 4.0, 5.0]
y_pred_example = [1.2, 2.3, 2.9, 4.2, 5.3]

# Call function
mae_value = loss_function_mae(y_true_example, y_pred_example)

# Output details
print("Mean Absolute Error (MAE): {:.4f}".format(mae_value))
Mean Absolute Error (MAE): 0.2200