Sebastian Chejniak
Sebastian Chejniak

Reputation: 1

How to train deepAR on multiple time series?

I am trying to use the GluonTS implementation of deepAR to train deepAR on multiple time series(using the m5 dataset). However, when I train deepAR on a single time series in the data set, the training takes just as little time as it does to train the model on 100(or more) time series. I have spend hours trying to understand what could be going wrong but I haven't found any potential solution. Here is code replicating the issue, assuming you have the m5 dataset downloaded:

from gluonts.mx import Trainer
from gluonts.evaluation import make_evaluation_predictions
from gluonts.model import deepar
from gluonts.mx.distribution.neg_binomial import NegativeBinomialOutput

import numpy as np
import pandas as pd

########################
##### PREPARING THE DATA
########################
prediction_length = 28
freq = "D"
start = pd.Timestamp("29-01-2011")

# load data
ste = pd.read_csv("sales_train_evaluation.csv")

# pandas Series of item 2
eva = ste.iloc[1,6:]

# 1-dimensional array containing time series data of item 2
item = np.array(ste.iloc[1,6:])

# Convert item to GluonTS-compatible ListDataset object
train_1 = ListDataset(
    [{'target': item[:-prediction_length], 'start':start}],
    freq=freq
)

# 2-dimensional array, containing time series data of 100 items
items = np.array(ste.iloc[1:101,6:])

# Convert to GluonTS-compatible ListDataset object
# train_100 contains 100 dictionaries, each corresponding to a given time series
train_100 = ListDataset(
    [{'target': ts, 'start':start} for ts in items[:, :-prediction_length]],
    freq=freq
)

########################
##### TRAINING THE MODEL
########################
nbo = NegativeBinomialOutput()
trainer = Trainer(epochs=5)

# train deepAR on 1 time series
estimator1 = deepar.DeepAREstimator(
    freq="D", prediction_length=28, trainer=trainer, distr_output=nbo
)
estimator1.train(training_data=train_1)

# train deepAR on 100 time series
estimator100 = deepar.DeepAREstimator(
    freq="D", prediction_length=28, trainer=trainer, distr_output=nbo
)
estimator100.train(training_data=train_100)

Upvotes: 0

Views: 1427

Answers (1)

Saravanan Natarajan
Saravanan Natarajan

Reputation: 375

Yes for 100 time series it will take time, are you using the gpu or cpu? In my I am using GPU so it works fine for me

estimator = SimpleFeedForwardEstimator(
                    num_hidden_dimensions=[10],
                    prediction_length=custom_ds_metadata['prediction_length'],
                    context_length=2*custom_ds_metadata['prediction_length'],
                    freq=custom_ds_metadata['freq'],
                    trainer=Trainer(
                        ctx="gpu",
                        epochs=5,
                        learning_rate=1e-3,
                        hybridize=False,
                        num_batches_per_epoch=100
                    )
                )`enter code here`

Upvotes: 1

Related Questions