title: Reshaping data to fit a multivariate LSTM time series model with time distributed wrapper
body: <p>I have a dataset comprising of hourly data from the past 7 years.</p>
  
  <p>I am trying to use train to predict one variable (price) 24 hours in advance, based on 168 hours (1 week) of historic data for all variables, including price.</p>
  
  <p>To do this I am attempting to build a NN with an LSTM layer and a time distributed layer, however am struggling to understand the shape coming of the data returning from each layer.</p>
  
  <p>My code is as follows:</p>
  
  <p><code>X_train.shape, Y_train.shape, X_valid.shape, Y_valid.shape, X_test.shape, Y_test.shape</code></p>
  
  <pre><code>((43800, 168, 6),
   (43800, 24),
   (8760, 168, 6),
   (8760, 24),
   (8574, 168, 6),
   (8574, 24))
  </code></pre>
  
  <p>So the training data (X) is made up of 43800 samples, looking back over 168 hours, for 6 features.
  The Y is 43800 samples, prediction for every hour for 24 hours in advance. This is currently where I am in attempting to run the model</p>
  
  <pre><code>model8 = keras.models.Sequential([
      keras.layers.LSTM(10, input_shape=(X_train.shape[1], X_train.shape[2]), return_sequences = True),
      keras.layers.LSTM(20, return_sequences= True),
      keras.layers.TimeDistributed(keras.layers.Dense(24))
  ])
  
  model8.compile(loss="mape", optimizer="adam")
  history = model8.fit(X_train, Y_train, epochs=2,
                      validation_data=(X_valid, Y_valid))
  
  ValueError: Error when checking target: expected time_distributed_26 to have shape (168, 24) but got array with shape (24, 1)
  
  </code></pre>
  
  <p>Any help would be greatly appreciated, as I don't fully understand why the time distributed layer expects all 168 hours of the past (with 24 features?), and not just the prediction of the future.</p>