# How to write a multivariate multi-step forecasting from a multivariate single step [closed]

I'm trying to implement a multi-variate, multiple-step model to forecast the day ahead electricity prices (h+1,h+2,...,h+24). I know how to do one forecast, but I'm confused with how to implement a multiple output approach where each forecast gives a vector of predictions for each hour in the day head for one shot (the multiple output strategy in https://machinelearningmastery.com/multi-step-time-series-forecasting/).

The gist of what I've done is get the code that predicts one time step, and modify it by converting the output into a sequence for the next 24 hours time shift, instead of just say one ElecPrice shifted 24 hours into the future:

Y['ElecPrice1'] = df['RT_LMP'].shift(-1)
Y['ElecPrice2'] = df['RT_LMP'].shift(-2)
Y['ElecPrice3'] = df['RT_LMP'].shift(-3)
...
Y['ElecPrice3'] = df['RT_LMP'].shift(-24)


I also changed the number of output signals my model has to predict.

Basically I made an entire 24 new columns instead of just one for my predictions. I have adjusted my dataset accordingly (no dangling NaNs, etc.). It seems too simple that I'm worrying if all I'm doing is making a prediction for one hour and copying that for the rest of the hours.

The sample code can be viewed in this link https://nbviewer.jupyter.org/github/Joichiro666/Forecasting-sharing/blob/master/LSTM-DNN%203.ipynb (ignore anything below generate predictions)

I just want to confirm if what I'm doing is correct or not.

• I could show you how to automate the creation of all the Y['ElecPrice3'] = df['RT_LMP'].shift(-24) lines, but if you aren't sure if the code is correct, it isn't on topic here. – Carcigenicate Oct 22 '19 at 22:33
• Yes, please. And, yes I'm also not sure if its correct - is there a more correct board for this question? – Joichiro Nishi Oct 22 '19 at 22:45

Similar to my recent review here, you can automate the simple repetition of each line by thinking about what's the same in each line, and what's different.

Each line seems to be, essentially:

Y['ElecPriceN'] = df['RT_LMP'].shift(-N)


The only thing that changes each time is N, so just loop over a range that generates numbers:

for n in range(1, 25):  # range(24) if you started at 0 instead of 1
Y['ElecPrice' + str(n)] = df['RT_LMP'].shift(-n)

• Construct a key string by taking n, stringifying it using str, then concatenating it to the name.

• Generate a shift value by just negating n. -n is the same as n * -1.

As for "I just want to confirm if what I'm doing is correct or not.", that's offtopic here, and too broad of a question for anywhere on Stack Exchange. A broad site like Reddit may be able to help you though.