title: In Keras, after you train a stateful LSTM model, do you have to re-train the model as you predict values?
body: <p>I've been trying to create a <code>stateful LSTM model</code> with <code>keras</code>, and I pretty much figured out the training part, but I don't get the predicting part.</p>
  <p>So, let's imagine that we had 10000 time-series datapoints. we use 9000 in front for training, and the other 1000 for testing. So, as we start training, we set the window length to 2, and slide the window forward as we set the input(<code>X</code>) as the first datapoint and set the output(<code>y</code>) as the second datapoint.
  <a href="https://i.stack.imgur.com/vxC0X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vxC0X.png" alt="X as input and y as output" /></a></p>
  <p>And as we train, the model converges because of it's stateful nature. Finally we finish training.</p>
  <p>Now, we are left with a model, and some test data. The problem begins here. We test the first datapoint.
  <a href="https://i.stack.imgur.com/v0WtM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/v0WtM.png" alt="enter image description here" /></a></p>
  <p>It returns a guessed value. Nice.</p>
  <p>We test the second datapoint of the test set.
  <a href="https://i.stack.imgur.com/Lt2Mf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Lt2Mf.png" alt="enter image description here" /></a></p>
  <p>We get an output. But, the problem is that because we were using a stateful model, and we only one value as an input, the only way the model is going to figure out the next value is from memory of the previous time-series.</p>
  <p>But since we didn't train the data on the <strong>first datapoint of the test set</strong>, the time-series is broken, and the model will think that the second datapoint on the test set is the first datapoint on the test set!</p>
  <p>So, my question is,</p>
  <ol>
  <li>does <code>keras</code> take care of this and automaticaly train the network as it's predicting?</li>
  <li>or do I have to train the net as I am predicting</li>
  <li>or is there some other reason that enables me to just keep predicting without training the model farther?</li>
  </ol>