title: How to use Keras TimeseriesGenerator to take a validation sample for every n training samples?
body: <p>I'm working on a time series forecasting problem using Keras library for neural networks. I'm trying to split the training set into actual training and validation sets. I don't want to take all the validation data from the end of my set, but rather take 1 validation test for every 5 training samples.</p>
  
  <p>I've managed to create two generators</p>
  
  <pre><code>training_sequence = TimeseriesGenerator(train_x, train_y, length=w, sampling_rate=1, batch_size=batch_s)
  validation_sequence = TimeseriesGenerator(train_x, train_y, length=w, sampling_rate=1, stride=5, batch_size=batch_s)
  </code></pre>
  
  <p>And I would use them for training like:</p>
  
  <pre><code>history = model.fit_generator(training_sequence, validation_sequence, epochs=200, callbacks=[early_stopping_monitor], verbose=1)  
  </code></pre>
  
  <p>Now, I'm obtaining the correct sequence for validation, but I can't figure out how to get these samples out of the training sequence (so that it's not validating on data it has already trained on).</p>
  
  <p>I've tried processing the training generator in a wrapper, like so:</p>
  
  <pre><code>def get_generator(data, targets, length, batch_size):
      data_gen = TimeseriesGenerator(data, targets, length=length, 
                                     sampling_rate=1, batch_size=batch_size)
      for i in range(len(data_gen)):
          if i % 5 != 0:
              x, y = data_gen[i]
              yield x, y
  </code></pre>
  
  <p>But when I run the code, I get this error:</p>
  
  <pre><code>ValueError: `steps_per_epoch=None` is only valid for a generator based on the `keras.utils.Sequence` class. Please specify `steps_per_epoch` or use the `keras.utils.Sequence` class.
  </code></pre>
  
  <p>If I add </p>
  
  <pre><code>steps_per_epoch=len(train_x)/batch_s
  </code></pre>
  
  <p>I get a "StopIteration" error.</p>