Merge pull request #39 from felipenv/master

- fix nmrse and forecast_step loop.
This commit is contained in:
Petrônio Cândido de Lima e Silva 2021-03-03 20:08:50 -03:00 committed by GitHub
commit 98d6b63cb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View File

@ -29,24 +29,30 @@ def acf(data, k):
return 1 / ((n - k) * sigma) * s
def rmse(targets, forecasts, order, steps_ahead):
def rmse(targets, forecasts, order=0, offset=0):
"""
Root Mean Squared Error
:param targets:
:param forecasts:
:param targets: array of targets
:param forecasts: array of forecasts
:param order: model order
:param offset: forecast offset related to target.
:return:
"""
if isinstance(targets, list):
targets = np.array(targets)
if isinstance(forecasts, list):
forecasts = np.array(forecasts)
return np.sqrt(np.nanmean((targets[order+steps_ahead:] - forecasts[:-steps_ahead]) ** 2))
if offset == 0:
return np.sqrt(np.nanmean((targets[order:] - forecasts[:]) ** 2))
else:
return np.sqrt(np.nanmean((targets[order+offset:] - forecasts[:-offset]) ** 2))
def nmrse(targets, forecasts, order, steps_ahead):
def nmrse(targets, forecasts, order=0, offset=0):
""" 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)
return rmse(targets, forecasts, order, offset) / (np.max(targets) - np.min(targets)) ## normalizing in targets because on forecasts might explode to inf (when model predict a line)

View File

@ -324,7 +324,7 @@ class FTS(object):
start = kwargs.get('start_at',0)
for k in np.arange(start+self.max_lag, l):
for k in np.arange(start+self.max_lag, l+1):
sample = data[k-self.max_lag:k]
tmp = self.forecast_ahead(sample, step, **kwargs)