The mean absolute percentage error (MAPE) is a metric that tells us how far apart our predicted values are from our observed values in a regression analysis, on average. It is calculated as:
MAPE = (1/n) * Σ(|Oi – Pi|/Oi * 100
where:
- Σ is a fancy symbol that means “sum”
- Pi is the predicted value for the ith observation
- Oi is the observed value for the ith observation
- n is the sample size
To find the MAPE for a regression, simply enter a list of observed values and predicted values in the two boxes below, then click the “Calculate” button:
Observed values:
Predicted values:
MAPE = 2.43242%
I think the formula for this is wrong when the observed values go negative, since this is not being converted to an absolute value, hence if it is negative this will produce a negative value which will skew the results.
The divisor should also be taken as the absolute value
You’re absolutely correct! The **Mean Absolute Percentage Error (MAPE)** formula should be carefully implemented, especially when dealing with datasets that may include negative or zero observed values. Here’s why:
1. **Observed Values Going Negative**:
If the observed values (\( y_i \)) are negative, the standard MAPE formula:
\[
MAPE = \frac{1}{n} \sum_{i=1}^n \frac{|y_i – \hat{y}_i|}{y_i}
\]
would indeed result in skewed results because the divisor (\( y_i \)) is not taken as its absolute value. This can cause the metric to return incorrect (and sometimes negative) percentages.
2. **Corrected Formula**:
To address this issue, the divisor should also use the absolute value of \( y_i \). The corrected formula is:
\[
MAPE = \frac{1}{n} \sum_{i=1}^n \frac{|y_i – \hat{y}_i|}{|y_i|}
\]
This ensures the calculation is consistent and avoids skewing the results when \( y_i \) is negative.
3. **Zero Observed Values**:
If \( y_i = 0 \), the formula becomes undefined due to division by zero. In such cases, a workaround is to exclude these points or replace them with a very small positive value (e.g., \( \epsilon \)) during the calculation.
### Why This Matters:
– In real-world applications, such as financial or demand forecasting, observed values can sometimes be negative (e.g., net loss or returns). Ignoring this can lead to inaccurate MAPE interpretations.
– Proper handling of negative values ensures the metric remains meaningful and comparable across datasets.
### Next Steps:
If you’re implementing this formula in a script or application, ensure you:
1. Take the **absolute value** of both the numerator and denominator during the calculation.
2. Handle cases where the observed value is zero to avoid undefined results.
Let me know if you’d like me to help with a Python implementation or adjustments to an existing script!