# How to predict value in every 120 minutes using LSTM in python

I want to predict value in every 120 minutes continuous using LSTM model. Here I wrote the code for predction. But I'm not getting proper prediction values . Here from start time I need to predict values in every 120 minutes.

model = Sequential()
# returns a sequence of vectors of dimension 32
model.add(LSTM(8, return_sequences=True))  # returns a sequence of vectors
of dimension 32
model.add(LSTM(8))  # return a single vector of dimension 32
batchsize = 1
history = model.fit(x_train_n,y_train_n, batch_size = batchsize,
nb_epoch=30,validation_data=(x_test_n, y_test_n),shuffle =True)\
model.reset_states()
pred1=model.predict(x_test_n)
pred2= model.predict(x_train_n)

#end of the sequences
model.reset_states()

#data=pd.DataFrame(fit1.predict(x_test))

pred1 = scaler_y.inverse_transform(np.array(pred1).reshape ((len(pred1), 1)))
real_test = scaler_y.inverse_transform(np.array(y_test_n).reshape
((len(y_test_n), 1))).astype(int)
real = scaler_y.inverse_transform(np.array(y_train_n).reshape
((len(y_train_n), 1))).astype(int)
pred1 = pred1[:,0]
real_test = real_test[:,0]

#predition in every 120 minutes

sequence_timestep = 120
last_sequence_train = x_train_n[-1]
pred1 = []
def sequence_constructor():
if len(pred1) >= sequence_timestep:
new_sequence = pred1[-dimension_seq:]
else:
splitter = sequence_timestep - len(pred1)
part_1 = last_sequence_train[-splitter:]
new_sequence = np.append(part_1,pred1) #Concatenate 2 list
new_sequence = np.array(new_sequence)
return new_sequence
for i in range(1440):
new_sequence = sequence_constructor()
new_prediction = model.predict(new_sequence)
pred1.append(new_prediction)


when I wrote this code error is coming and it's not predicting the values properly. Here I upload my csv file also, and I wrote what I'm trying to do to predict my value. In my csv file g and p in my two inputs. When the prediction values in every 120 minutes will be the next input of my LSTM . According to my csv file 10/3/2018 start time = 6:00:00 a.m from that predict the g values in every 120 minutes. Then again next day start time is again 6:00:00 a.m from that time again new prediction values in every 120 minutes.