6

I understand how to create models for a Multivariate time series and also know how to produce a multistep output for that series. But how can I expand this model to work on multiple time series?

My data contains a time series for many countries and for each country there are 5 features. My goal is to produce forecasts for a 28 days ahead for each country.

Here is a plot of one multivariate time series (one of the features is not shown in the plot): enter image description here

The following model is an Encoder Decoder LSTM capable of producing 28 days worth of predictions (although they are not very accurate):

Model: "sequential_1"
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
lstm_1 (LSTM)                (None, 10)                640
_________________________________________________________________
repeat_vector_1 (RepeatVecto (None, 7, 10)             0
_________________________________________________________________
lstm_2 (LSTM)                (None, 7, 10)             840
_________________________________________________________________
time_distributed_1 (TimeDist (None, 7, 5)              55
=================================================================
Total params: 1,535
Trainable params: 1,535
Non-trainable params: 0
_________________________________________________________________

The training data is split into 7 day periods where each period is one day ahead of the previous. Example (but with one feature instead of 5):

[1, 2, 3, 4, 5, 6, 7], [2, 3, 4, 5, 6, 7, 8] ...

The data given to the LSTM has the following shapes:

Train_x shape: (113, 7, 5)
Train_y shape: (113, 7, 5)
Test shape: (4, 7, 5)

How to do this for 187 countries?

I found an answer saying that it is possible to use the country's name as a variable during the training process. And another one showing how to merge the time series data with the categorical values.

In the second thread the best approach consists of adding (or setting) the weights of the recurrent layer with a learnt representation of the categorical data. Basically pass the country name by a Dense layer and add that output to the LSTM weights.

I found a discussion about setting the weights of a layer in Keras but it doesn't show how to add the weights.

My main questions are:

  • If all nodes have to be connected in a Keras model where does the Dense layer for the names go?
  • How to add the weights instead of overwriting them (does it make a difference)?
  • Is there a better way of forecasting multiple time series?
  • How bad would it be to simply retrain the model on each country's data?
Marcus
  • 289
  • 1
  • 3
  • 19

0 Answers0