-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.py
39 lines (30 loc) · 886 Bytes
/
metrics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 8 10:31:02 2020
@author: darmo
"""
import numpy as np
def smape(a, b):
"""
Calculates sMAPE
:param a: actual values
:param b: predicted values
:return: sMAPE
"""
a = np.reshape(a, (-1,))
b = np.reshape(b, (-1,))
return np.mean(2.0 * np.abs(a - b) / (np.abs(a) + np.abs(b))).item()
def mase(insample, y_test, y_hat_test, freq):
"""
Calculates MAsE
:param insample: insample data
:param y_test: out of sample target values
:param y_hat_test: predicted values
:param freq: data frequency
:return:
"""
y_hat_naive = []
for i in range(freq, len(insample)):
y_hat_naive.append(insample[(i - freq)])
masep = np.mean(abs(insample[freq:] - y_hat_naive))
return np.mean(abs(y_test - y_hat_test)) / masep