title: How can I get predicted the following value of stock using predict method of Tensorflow?
body: <p>I am wondering how to predict and get future time series data after model training. I would like to get the values after N steps. I wonder if the time series data has been properly learned and predicted. How do I do this right to get the following(next) value? I want to get the next value using <code>model.predict</code> or similar.</p>
  <p>I have <code>x_test</code> and <code>x_test[-1] == t</code> So, the meaning of the next value is <code>t+1, t+2, .... t+n</code>. In this example <strong>I want to get <code>t+1, t+2 ... t+n</code></strong></p>
  <h1>First</h1>
  <p>I tried using stock index data</p>
  <pre><code>inputs = total_data[len(total_data) - forecast - look_back:]
  inputs = scaler.transform(inputs)
  X_test = []
  for i in range(look_back, inputs.shape[0]):
      X_test.append(inputs[i - look_back:i])
  X_test = np.array(X_test)
  predicted = model.predict(X_test)
  </code></pre>
  <p>but the result is like below</p>
  <p><a href="https://i.stack.imgur.com/L6qL1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L6qL1.png" alt="enter image description here" /></a></p>
  <p>The results from <code>X_test[-20:]</code> and the following 20 <strong>predictions looks like same.</strong> I'm wondering if it's the correct method to train and predicted value and also if the result was correct.</p>
  <p><a href="https://gist.github.com/Lay4U/2e1759a0e435ff95b7a017e301db634f" rel="nofollow noreferrer">full source</a></p>
  <p>The method I tried first did not work correctly.</p>
  <h1>Second</h1>
  <p>I realized something is wrong, I tried using another official data so I used the time series in the <strong>Tensorflow tutorial</strong> to practice training the model.</p>
  <pre><code>a = y_val[-look_back:] 
  for i in range(N-step prediction): #predict a new value n times.
      tmp = model.predict(a.reshape(-1, look_back, num_feature)) #predicted value     
      a = a[1:] #remove first     
      a = np.append(a, tmp) #insert predicted value
  </code></pre>
  <p>The results were predicted in a linear regression shape very differently from the real data.</p>
  <p><img src="https://imgur.com/7tenqRd.png" alt="2" /></p>
  <p>Output a linear regression abnormal that is independent of the real data:</p>
  <p><a href="https://gist.github.com/Lay4U/96e0ba8d8c251046e89eae4bc5d40510" rel="nofollow noreferrer">full source</a>  (After the 25th line is my code.)</p>
  <p>I'm really very curious that <strong>How can I predict the following value of time series using Tensorflow predict method</strong></p>
  <p>I'm not wondering if this works or not theoretically. I'm just wondering how to <strong>get the following n steps using the predict method.</strong></p>
  <p>Thank you for reading the long question. I seek advice about your priceless opinion.</p>