loss_function_mape
Loss function: Mean Absolute Percentage Error.
mape = loss_function_mape(y_true, y_pred)
Input variables
Name | Description | Type |
---|---|---|
y_true | True values | List |
y_pred | Predicted values | List |
Output variables
Name | Description | Type |
---|---|---|
mape | Mean Absolute Percentage Error | Float |
Problem
\[f(\mathbf{y}_{\text{true}}, \mathbf{y}_{\text{pred}}) = \frac{1}{n} \cdot \sum_{i=1}^{n} \left| \frac{y_{\text{true},i} - y_{\text{pred},i}}{y_{\text{true},i}} \right| \times 100\] | (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 Percentage Error (MAPE)?
# Example 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
mape_value = loss_function_mape(y_true_example, y_pred_example)
# Output details
print("Mean Absolute Percentage Error (MAPE): {:.4f}".format(mape_value))
Mean Absolute Percentage Error (MAPE): 9.8667