Merge pull request #39 from felipenv/master
- fix nmrse and forecast_step loop.
This commit is contained in:
commit
98d6b63cb4
@ -29,24 +29,30 @@ def acf(data, k):
|
|||||||
return 1 / ((n - k) * sigma) * s
|
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
|
Root Mean Squared Error
|
||||||
|
|
||||||
:param targets:
|
:param targets: array of targets
|
||||||
:param forecasts:
|
:param forecasts: array of forecasts
|
||||||
|
:param order: model order
|
||||||
|
:param offset: forecast offset related to target.
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
if isinstance(targets, list):
|
if isinstance(targets, list):
|
||||||
targets = np.array(targets)
|
targets = np.array(targets)
|
||||||
if isinstance(forecasts, list):
|
if isinstance(forecasts, list):
|
||||||
forecasts = np.array(forecasts)
|
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 """
|
""" 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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ class FTS(object):
|
|||||||
|
|
||||||
start = kwargs.get('start_at',0)
|
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]
|
sample = data[k-self.max_lag:k]
|
||||||
tmp = self.forecast_ahead(sample, step, **kwargs)
|
tmp = self.forecast_ahead(sample, step, **kwargs)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user