简体   繁体   中英

LSTM for time series

I'm trying to build a predictive model using an LSTM; briefly to predict " target ", using the series " data ". After a few epochs, it correctly fits the data. As a beginner, what kind of dataset (dimensions) do I have to feed the network with, in order to give me further predictions?

My aim is to predict +1 step, given the whole past time series, how can I implement it?

Ultimately, what does the second 1 stand for, when I reshape "data", and "target"?

print(df.head)
0            7        20
1            0         0
2            0         0
3            0         0
4            0         0
...

data = df[:,0]
target = df[:, 1 ]

data = data.reshape((1, 1, int(len(df)))) 
target = target.reshape((1 ,1, int(len(df)))) 
#We Define The Model
import random
random.seed(1)

model = Sequential()  
model.add(LSTM(int(len(df)), input_shape=(1, int(len(df))), return_sequences=True))
model.add(Dense(int(len(df))))

model.add(LSTM(int(len(df)), input_shape=(1, int(len(df))), return_sequences=True))
model.add(Dense(int(len(df))))

model.compile(loss='mean_absolute_error', optimizer='Adam',metrics=['accuracy'])

model.fit(data, target, nb_epoch=100, batch_size=1, verbose=2, validation_data = (data, target))

predict = model.predict(data)

I think you are using Keras to develop your LSTM model. I will suggest you look at the following link (below) to understand more carefully why one need to reshape the data. In the example, the dimensions of your dataframe are same as the tutorial is using.

https://machinelearningmastery.com/time-series-prediction-lstm-recurrent-neural-networks-python-keras/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM