Skip to content

Commit 59c7d1b

Browse files
committed
- add metric compute WAPE
1 parent 8a8efe7 commit 59c7d1b

File tree

1 file changed

+27
-0
lines changed
  • evo_science/entities/metrics

1 file changed

+27
-0
lines changed

evo_science/entities/metrics/wape.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import numpy as np
2+
3+
from evo_science.entities.metrics import BaseMetric
4+
5+
6+
class WAPE(BaseMetric):
7+
"""
8+
WAPE (Weighted Absolute Percentage Error) is a metric used to measure the accuracy of a forecasting model.
9+
It is calculated as the ratio of the sum of absolute errors to the sum of actual values, multiplied by 100.
10+
11+
Formula:
12+
WAPE = (sum(|y_true - y_pred|) / sum(y_true)) * 100
13+
"""
14+
name = "WAPE"
15+
16+
def _calculate_np(self, y_true: np.array, y_pred: np.array):
17+
"""
18+
Calculate WAPE using numpy arrays.
19+
"""
20+
absolute_errors = np.abs(y_true - y_pred)
21+
sum_absolute_errors = np.sum(absolute_errors)
22+
sum_actual_values = np.sum(y_true)
23+
wape = (sum_absolute_errors / sum_actual_values) * 100
24+
return wape
25+
26+
27+

0 commit comments

Comments
 (0)