# LSTM with input of actual time step

I'm working on an implementation of LSTM neural network to forecast energy consumption. I have a dataset with load, series of weather parameters and indicator of it's bank holiday or not.

I first did a network with input of 24 lag (using function from this tutorial). So I have a dataset like this, but with 18 variables and from ($$t_{-24}$$)

   var1(t-1)  var2(t-1)  var1(t)  var2(t)
1        0.0       50.0        1       51
2        1.0       51.0        2       52
3        2.0       52.0        3       53
4        3.0       53.0        4       54
5        4.0       54.0        5       55
6        5.0       55.0        6       56
7        6.0       56.0        7       57
8        7.0       57.0        8       58
9        8.0       58.0        9       59


And I have my LSTM network:

model = Sequential()


And currently I use var1(t-1) and var2(t-1) to predict var2(t) value. But var2 is correlated with value of var1. I have value var1(t) and I want to use it to predict var2(t), but I don't know how to do that.

I tried to fit my neural network with var1(t-1), var2(t-1) and var1(t) but it don't match with then input matrix which is (value, lagged hours, number of variables)

• what is the question?! Commented Aug 8, 2019 at 0:22

I'm not sure whether I understand the question, but if you want to include var1(t) along with the other lagged features var1(t-1), var2(t-2), etc. you can simply add var1(t) as an additional feature. This means that your matrix with previous shape

(number of samples, number of timesteps, old number of features)


now becomes

(number of samples, number of timesteps, new number of features = old number of features + 1)


Judging from your code this can be simply done by adding var1(t) as a new column to your train_X matrix, like in the first three columns of your first code snippet.

However I'm not sure why you want to do this. Forecasting at time t usually assumes that, once your model is ready to work on real data, you won't have any data at t, only from the past. If you build your model based on data at time t without being able to retrieve these information once in production, then you've got a problem! Also, you write that var1 and var2 are correlated, hence the LSTM is already picking up this correlation as you are feeding past values of these variables together.

• Thanks for your advice. In my case predicted load is different if day is a work day or bank holiday like New Year or Easter. So I need have this information form actual tilmestep. Also I have weather data from forecast api and I want to test if it make my predictions better. Commented Aug 8, 2019 at 17:55
• And your advice with adding +1 feature it won't work. I tested it. The input form LSTM is like I said (number of samples, number of hours , number of feuatures) number of samples is number of timestamps so for example 2016-02-02 00:00:00 2016-02-02 01:00:00 2016-02-02 03:00:00 and then number of hours mens number of lag in my case 24, and number of features is number of features in every hour, not in all hours. Commented Aug 8, 2019 at 17:55
• Could you please provide your two examples of train_X from your the data of your first code snippet, one without (the one that works) and one with (the one that doesn't work) var1(t)? Commented Aug 9, 2019 at 7:36