0

here is my code

...
look_back = 20
train_size = int(len(data) * 0.80)
test_size = len(data) - train_size

train = data[0:train_size]
test = data[train_size:len(data)]
x_train, y_train = create_dataset(train, look_back)
x_test, y_test = create_dataset(test, look_back)

x_train = np.reshape(x_train, (x_train.shape[0], x_train.shape[1], 1))
x_test = np.reshape(x_test, (x_test.shape[0], x_test.shape[1], 1))
y_train=np.repeat(y_train.reshape(-1,1), 20, axis=1).reshape(-1,20,1)
y_test=np.repeat(y_test.reshape(-1,1), 20, axis=1).reshape(-1,20,1)
...
model = Sequential()

model.add(LSTM(512,  return_sequences=True))
model.add(Dropout(0.3))

model.add(LSTM(512,  return_sequences=True))
model.add(Dropout(0.3))

model.add(LSTM(1, return_sequences=True))

model.compile(loss='mean_squared_error', optimizer='rmsprop', metrics=['accuracy'])
model.summary()
model.fit(x_train, y_train, epochs=10, batch_size=64)
p = model.predict(x_test)

and I want to predict the next value So, predictions = model.predict(x_train) and shape is (62796, 20, 1)

and I coded the following site how to use the Keras model to forecast for future dates or events?

future = []
currentStep = predictions[-20:, :, :] # -20 is last look_back number

for i in range(10):
    currentStep = model.predict(currentStep)
    future.append(currentStep)

in this code future's result is

1

but p = model.predict(x_test)'s [:4000] result is

2

I want to know how to predict the exact next value.

But, The difference between the two results is very large.

what is the right way to Predict the next value??

I don't know where it went wrong or the code went wrong.

I hope for your opinion.

full source is https://gist.github.com/Lay4U/654f70bd1fb9c4f7d5bdb21ddcb588ab

GoBackess
  • 404
  • 3
  • 17
  • if you have your x_test data then, predict the first sample y1 = clf.predict(x_test[0]) this should predict the first class, and then predict the next sample y2 = clf.predict(x_test[1]) – Freddy Daniel May 30 '19 at 23:51
  • i did ```model.prediction(predictions[-20:, :, :]``` – GoBackess May 31 '19 at 02:23

0 Answers0