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))