Data Science Asked on February 14, 2021
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()
model.add(LSTM(50, input_shape=(train_X.shape[1], train_X.shape[2])))
model.add(Dense(1))
model.compile(loss='mae', optimizer='Adam')
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)
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.
Answered by black_cat on February 14, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP