Considering we have trained our model with a lot of data for "many-to-one" prediction. Then we like to forecast the future data of next 10 days. So we use last 60 of existent data and predict the single next day. From here there are 2 approaches:
We can put our
model.predict()
function in afor
loop for 10 times and do predictions like this(adding our predictions to end of our real data).We can put all of our model(consisting training part, not just predict part), in a
for
loop and this means we train our model 10 times whenever we do a new prediction and adding it to our real data.
EDIT:
Thinking you have X_train = (100,60,1)
array that means 100 examples, 60 time-steps(hidden units) and 1 feature for each example. Also you have y_train
array of size (100,1,1)
that means 100 labels with time-steps = 1 and 1 feature. Then you train your network to read 60 of inputs and predict the next single output. Also you create a X_test
array like this: X_test = X_train[len(X_train - 60):]
that means you use last 60 numbers of your series to predict the next number. So you use the new_number = model.predict(X_test)
for that and you predict the time-step 61 that is not a real number. It's your prediction. Then you want to continue your predictions. So what do you do is adding the 61'th predicted number to the last of your X_test = np.append(X_test, new_number)
and do new number = model.predict(X_test)
again. But the difference is that the last number in your new X_test
is your previous prediction. And you keep this way for 10 times to predict 10 next numbers. (This was the first approach).
The other approach(2) has a difference. After doingnew_number = model.predict(X_test)
for the first time, you add the predicted number to x_train
instead of X_test
, like this X_train = np.append(X_train, new_number)
and train your model again model.fit(X_train , y_train)
with the new predicted number. Then you use new number = model.predict(X_test)
and again adding predicted number into the X_train
, then train your model again(this time, with 2 new predicted numbers that you have added to the end of your X_train
) and so on for 10 times!