Seasonal Naive method is not available
import pandas as pd
import numpy as np
import mxnet as mx
from mxnet import gluon
from gluonts.dataset import common
from gluonts.model.seasonal_naive import SeasonalNaiveEstimator
from gluonts.trainer import Trainer
N = 10 # number of time series
T = 100 # number of timesteps
prediction_length = 24
custom_dataset = np.random.normal(size=(N, T))
start = pd.Timestamp("01-01-2019", freq='1H') # can be different for each time series
print(custom_dataset.shape)
print(custom_dataset)
# train dataset: cut the last window of length "prediction_length", add "target" and "start" fields
train_ds = [{'target': x, 'start': start} for x in custom_dataset[:, :-prediction_length]]
# test dataset: use the whole dataset, add "target" and "start" fields
test_ds = [{'target': x, 'start': start} for x in custom_dataset]
estimator = SeasonalNaiveEstimator(
prediction_length=prediction_length,
context_length=100,
freq='1H',
trainer=Trainer(ctx="cpu")
)
from gluonts.model.seasonal_naive import SeasonalNaiveEstimator
ModuleNotFoundError: No module named 'gluonts.model.seasonal_naive'
@alexhallam this was moved, you can do from gluonts.model.baseline import SeasonalNaivePredictor. Could you confirm that this import works?
Note that this is a predictor and not an estimator, since it doesn’t require offline training.
Seems to be getting closer. I got an ModuleNotFoundError: No module named 'statsmodels' error. I am installing statsmodels now.
Works like a charm! Thanks.
A couple of points on documentation:
statsmodels was requirednum_samples was needed, but num_eval_samples was in docsI am not sure if I will be able to add documentation, but if you point me in the right direction I may be able to fix those problems.
import pandas as pd
import numpy as np
import mxnet as mx
from mxnet import gluon
from gluonts.dataset import common
from gluonts.model.baseline import SeasonalNaivePredictor
from gluonts.trainer import Trainer
from gluonts.evaluation.backtest import make_evaluation_predictions
N = 10 # number of time series
T = 100 # number of timesteps
prediction_length = 24
custom_dataset = np.random.normal(size=(N, T))
start = pd.Timestamp("01-01-2019", freq='1H') # can be different for each time series
# train dataset: cut the last window of length "prediction_length", add "target" and "start" fields
train_ds = [{'target': x, 'start': start} for x in custom_dataset[:, :-prediction_length]]
# test dataset: use the whole dataset, add "target" and "start" fields
test_ds = [{'target': x, 'start': start} for x in custom_dataset]
predictor = SeasonalNaivePredictor(
prediction_length=prediction_length,
season_length=24,
freq='1H'
)
forecast_it, ts_it = make_evaluation_predictions(
dataset=test_ds, # test dataset
predictor=predictor, # predictor
num_samples=100, # number of sample paths we want for evaluation
)
forecasts = list(forecast_it)
tss = list(ts_it)
print(forecasts[0].quantile(0.5))
import pandas as pd
import numpy as np
import mxnet as mx
from mxnet import gluon
from gluonts.dataset import common
from gluonts.model.baseline import SeasonalNaivePredictor
from gluonts.trainer import Trainer
from gluonts.evaluation.backtest import make_evaluation_predictions
N = 10 # number of time series
T = 100 # number of timesteps
prediction_length = 24
custom_dataset = np.random.normal(size=(N, T))
start = pd.Timestamp("01-01-2019", freq='1H') # can be different for each time series
# train dataset: cut the last window of length "prediction_length", add "target" and "start" fields
train_ds = [{'target': x, 'start': start} for x in custom_dataset[:, :-prediction_length]]
# test dataset: use the whole dataset, add "target" and "start" fields
test_ds = [{'target': x, 'start': start} for x in custom_dataset]
predictor = SeasonalNaivePredictor(
prediction_length=prediction_length,
season_length=24,
freq='1H'
)
forecast_it, ts_it = make_evaluation_predictions(
dataset=test_ds, # test dataset
predictor=predictor, # predictor
num_samples=100, # number of sample paths we want for evaluation
)
forecasts = list(forecast_it)
tss = list(ts_it)
print(f"Number of sample paths: {forecasts[0].num_samples}")
print(f"Dimension of samples: {forecasts[0].samples.shape}")
print(f"Start date of the forecast window: {forecasts[0].start_date}")
print(f"Frequency of the time series: {forecasts[0].freq}")
print(f"Mean of the future window:\n {forecasts[0].mean}")
print(f"0.2-quantile of the future window:\n {forecasts[0].quantile(0.2)}")
print(f"0.5-quantile (median) of the future window:\n {forecasts[0].quantile(0.5)}")
print(f"0.8-quantile of the future window:\n {forecasts[0].quantile(0.8)}")
I noticed that num_samples does not seem to be used. The output of the above is:
Number of sample paths: 1
Dimension of samples: (1, 24)
Start date of the forecast window: 2019-01-04 04:00:00
Frequency of the time series: 1H
Mean of the future window:
[ 0.44458964 -1.3713677 -1.1218287 0.9637291 -1.9008862 1.0164506
-0.28062356 -0.14012817 1.79892 -1.3410987 -1.2254264 -1.6468405
0.45498142 -0.02876565 -1.4428202 0.3965213 -0.20520817 2.306088
-0.12756906 1.3810035 -1.4139321 -0.44692338 -1.7753316 0.54498607]
0.2-quantile of the future window:
[ 0.44458964 -1.3713677 -1.1218287 0.9637291 -1.9008862 1.0164506
-0.28062356 -0.14012817 1.79892 -1.3410987 -1.2254264 -1.6468405
0.45498142 -0.02876565 -1.4428202 0.3965213 -0.20520817 2.306088
-0.12756906 1.3810035 -1.4139321 -0.44692338 -1.7753316 0.54498607]
0.5-quantile (median) of the future window:
[ 0.44458964 -1.3713677 -1.1218287 0.9637291 -1.9008862 1.0164506
-0.28062356 -0.14012817 1.79892 -1.3410987 -1.2254264 -1.6468405
0.45498142 -0.02876565 -1.4428202 0.3965213 -0.20520817 2.306088
-0.12756906 1.3810035 -1.4139321 -0.44692338 -1.7753316 0.54498607]
0.8-quantile of the future window:
[ 0.44458964 -1.3713677 -1.1218287 0.9637291 -1.9008862 1.0164506
-0.28062356 -0.14012817 1.79892 -1.3410987 -1.2254264 -1.6468405
0.45498142 -0.02876565 -1.4428202 0.3965213 -0.20520817 2.306088
-0.12756906 1.3810035 -1.4139321 -0.44692338 -1.7753316 0.54498607]
I was expecting to get quantiles from a normal distribution as described here.
Seems to be getting closer. I got an
ModuleNotFoundError: No module named 'statsmodels'error. I am installingstatsmodelsnow.
This is something we should fix
statsmodelswas required
This is not right, we’ll have to change this and get back to you
num_sampleswas needed, butnum_eval_sampleswas in docs
Can you point me to the specific section in the docs? It used to be that (and so it is still that in the docs of the stable release) then we changed it (so on the “latest” documentation it should be correct)
I was expecting to get quantiles from a normal distribution as described here.
That’s model dependent: some models in gluonts yield predictive distributions in the form of sample paths, in which case that parameter has an effect. Other models may return distributions in parametric form, or just point forecasts (like in your case), and in these cases that parameter is essentially ignored.
I hope this clarifies it, but I understand however that this may create confusion.
statsmodelswas requiredThis is not right, we’ll have to change this and get back to you
num_sampleswas needed, butnum_eval_sampleswas in docsCan you point me to the specific section in the docs? It _used to be_ that (and so it is still that in the docs of the stable release) then we changed it (so on the “latest” documentation it should be correct)
I thought I saw it in the tutorial here on block 15, but now is says num_samples. So there is no problem.
By the way, this is essentially the naive seasonal method of section 3.1 in the same book: https://otexts.com/fpp2/simple-methods.html
By the way, this is essentially the naive seasonal method of section 3.1 in the same book: https://otexts.com/fpp2/simple-methods.html
yeah, I was looking for a seasonal method that generates a distribution so I could get quantiles.
where

and

where c is the coverage probability, h is the forecast horizon, m is the length of the seasonal period,
I still may be able to get this to work by calculating these values on my own, but if you know of something that is out of the box I would be interested.
@alexhallam note that with #788 we’ve put back the seasonal naive method where it belongs: if you pull the latest commit you should be able to do
from gluonts.model.seasonal_naive import SeasonalNaivePredictor
In particular, statsmodels is now not required to run the above import.