From d5c4482f2086b8e3e4d60a393c61b6cbac30ed63 Mon Sep 17 00:00:00 2001 From: Felipe Vianna Date: Tue, 23 Feb 2021 14:32:46 +0100 Subject: [PATCH] - fix rmse: aligned targets and forecasts for calculation - implement nmrse --- pyFTS/benchmarks/Measures.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pyFTS/benchmarks/Measures.py b/pyFTS/benchmarks/Measures.py index bdc5000..260a975 100644 --- a/pyFTS/benchmarks/Measures.py +++ b/pyFTS/benchmarks/Measures.py @@ -29,7 +29,7 @@ def acf(data, k): return 1 / ((n - k) * sigma) * s -def rmse(targets, forecasts): +def rmse(targets, forecasts, order, steps_ahead): """ Root Mean Squared Error @@ -41,9 +41,15 @@ def rmse(targets, forecasts): targets = np.array(targets) if isinstance(forecasts, list): forecasts = np.array(forecasts) - return np.sqrt(np.nanmean((targets - forecasts) ** 2)) + return np.sqrt(np.nanmean((targets[order+steps_ahead:] - forecasts[:-steps_ahead]) ** 2)) +def nmrse(targets, forecasts, order, steps_ahead): + """ Normalized Root Mean Squared Error """ + return rmse(targets, forecasts, order, steps_ahead) / (np.max(targets) - np.min(targets)) ## normalizing in targets because on forecasts might explode to inf (when model predict a line) + + + def rmse_interval(targets, forecasts): """ Root Mean Squared Error