File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
evo_science/entities/metrics Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments