title: Multivariate time series predictions with RNN - LSTM using Keras
body: <p>I want to build a model in order to perform anomaly detection in multivariate time series. Indeed, I have 21 features which are 21 time series for each time-window. The method lays on RNN - LSTM with Keras, the training is done on 100 time-windows considered as normal data and the objective is to apply the model on a new time window so as to detect whether some time-instances are considererd as abnormal. 
  The model predicts the next instance of each feature, so there are 21 outputs of the model.</p>
  
  <p>My "normal" data are shaped like this:
  100 time windows with 1650 observations and 21 features.</p>
  
  <p>My way is to build a model to predict the t+1 instance of a vector of 21 features , so I try to shape X and Y giving:</p>
  
  <pre><code>train_X.shape = (80, 1649, 21)
  
  train_Y.shape = (80, 1649, 21) 
  </code></pre>
  
  <p>train_Y is the t+1 vector of the train_X vector.</p>
  
  <p>I also have a validation set in the training process (to tackle overfitting)</p>
  
  <pre><code>test_X.shape = (20, 1649, 21)
  
  test_Y.shape = (20,1649, 21)
  </code></pre>
  
  <p>I found this code on machinelearningmastery.com and tried to deal with it:</p>
  
  <pre><code>config = {'sequence_length': 100, 'epochs': 120, 'batch_size': 30, 
  'validation_split': 0.2}
  layers = {'input': 21, 'hidden1': 60, 'hidden2':60, 'output': 21}
  
  model = Sequential()
  
  model.add(LSTM(output_dim=4, layers['hidden1'], input_shape=(1649, 21), 
  return_sequences=True))
  model.add(Dropout(config['validation_split']))
  
  model.add(LSTM(units=layers['hidden2'], return_sequences=False) )
  model.add(Dropout(config['validation_split']))
  
  model.add(Dense(units=layers['output']))
  
  model.add(Activation("linear"))
  
  model.add(Dense(1))
  
  model.compile(loss='mse', optimizer='rmsprop')
  </code></pre>
  
  <p>Fit network</p>
  
  <pre><code>history = model.fit(train_X, train_y, epochs=config['epochs'], 
  batch_size=config['batch_size'], validation_data=(test_X, test_y), 
  verbose=2, shuffle=False)
  print("Predicting...")
  predicted = model.predict(test_X)
  print("Reshaping predicted")
  predicted = np.reshape(predicted, (predicted.size,))
  </code></pre>
  
  <p>Do you think I have the right approach? Someone could give me some tips to modify the code or the shaping of the data ?</p>
  
  <p>Thanks.</p>