mirror of
https://github.com/wassname/seq2seq-time.git
synced 2026-06-27 19:00:55 +08:00
24 lines
684 B
Python
24 lines
684 B
Python
import numpy as np
|
|
|
|
EPSILON = 1e-10
|
|
|
|
def _error(actual: np.ndarray, predicted: np.ndarray):
|
|
""" Simple error """
|
|
return actual - predicted
|
|
|
|
def mse(actual: np.ndarray, predicted: np.ndarray):
|
|
""" Mean Squared Error """
|
|
return np.mean(np.square(_error(actual, predicted)))
|
|
|
|
def rmse(actual: np.ndarray, predicted: np.ndarray):
|
|
""" Root Mean Squared Error """
|
|
return np.sqrt(mse(actual, predicted))
|
|
|
|
|
|
def smape(actual: np.ndarray, predicted: np.ndarray):
|
|
"""
|
|
Symmetric Mean Absolute Percentage Error
|
|
Note: result is NOT multiplied by 100
|
|
"""
|
|
return np.mean(2.0 * np.abs(actual - predicted) / ((np.abs(actual) + np.abs(predicted)) + EPSILON))
|