title: Time Series prediction using RNNs (Keras) in R
body: <p>I was following the Chollet's Deep learning with R approach (<a href="https://blogs.rstudio.com/tensorflow/posts/2017-12-20-time-series-forecasting-with-recurrent-neural-networks/" rel="nofollow noreferrer">fitting RNNs to time series data</a>) for fitting RNNs for time series prediction.</p>
  
  <pre><code>model &lt;- keras_model_sequential() %&gt;% 
    layer_gru(units = 32, 
              dropout = 0.1, 
              recurrent_dropout = 0.5,
              return_sequences = TRUE,
              input_shape = list(NULL, dim(data)[[-1]])) %&gt;% 
    layer_gru(units = 64, activation = "relu",
              dropout = 0.1,
              recurrent_dropout = 0.5) %&gt;% 
    layer_dense(units = 1)
  
  model %&gt;% compile(
    optimizer = optimizer_rmsprop(),
    loss = "mae"
  )
  
  history &lt;- model %&gt;% fit_generator(
    train_gen,
    steps_per_epoch = 500,
    epochs = 40,
    validation_data = val_gen,
    validation_steps = val_steps
  )
  </code></pre>
  
  <p>Here, train, validation and tests data are generated using:</p>
  
  <pre><code>lookback &lt;- 1440
  step &lt;- 6
  delay &lt;- 144
  batch_size &lt;- 128
  
  train_gen &lt;- generator(
    data,
    lookback = lookback,
    delay = delay,
    min_index = 1,
    max_index = 200000,
    shuffle = TRUE,
    step = step, 
    batch_size = batch_size
  )
  
  val_gen = generator(
    data,
    lookback = lookback,
    delay = delay,
    min_index = 200001,
    max_index = 300000,
    step = step,
    batch_size = batch_size
  )
  
  test_gen &lt;- generator(
    data,
    lookback = lookback,
    delay = delay,
    min_index = 300001,
    max_index = NULL,
    step = step,
    batch_size = batch_size
  )
  
  # How many steps to draw from val_gen in order to see the entire validation set
  val_steps &lt;- (300000 - 200001 - lookback) / batch_size
  
  # How many steps to draw from test_gen in order to see the entire test set
  test_steps &lt;- (nrow(data) - 300001 - lookback) / batch_size
  </code></pre>
  
  <p>After this, I have read the Keras documentation and found the prediction function. To find the prediction on test data:</p>
  
  <pre><code>m &lt;- model %&gt;% evaluate_generator(test_gen, steps = test_steps)
  m
  </code></pre>
  
  <p>However, It giving only loss value for test data.</p>
  
  <p>My question is, how to get the predictions for each point in test dataset, like we can get in other time series method? How to plot these predicted and actual values? </p>