title: LSTM Keras input shape confusion
body: <p>I am trying to build a predictive model on stock prices. From what I've read, LSTM is a good layer to use. I can't fully understand what my <code>input_shape</code> needs to be for my model though.</p>
  
  <p>Here is the <code>tail</code> of my <code>DataFrame</code></p>
  
  <p><a href="https://i.stack.imgur.com/x2iZk.png" rel="noreferrer"><img src="https://i.stack.imgur.com/x2iZk.png" alt="print(x_test.shape)"></a></p>
  
  <p>I then split the data into train / test</p>
  
  <pre><code>labels = df['close'].values
  x_train_df = df.drop(columns=['close'])
  x_train, x_test, y_train, y_test = train_test_split(x_train_df.values, labels, test_size=0.2, shuffle=False)
  
  min_max_scaler = MinMaxScaler()
  x_train = min_max_scaler.fit_transform(x_train)
  x_test = min_max_scaler.transform(x_test)
  
  print('y_train', y_train.shape)
  print('y_test', y_test.shape)
  print('x_train', x_train.shape)
  print('x_test', x_test.shape)
  print(x_train)
  </code></pre>
  
  <p>This yields:</p>
  
  <p><a href="https://i.stack.imgur.com/9TKXf.png" rel="noreferrer"><img src="https://i.stack.imgur.com/9TKXf.png" alt="enter image description here"></a></p>
  
  <p>Here's where I am getting confused. Running the simple example, I get the following error:</p>
  
  <blockquote>
    <p>ValueError: Input 0 of layer lstm_15 is incompatible with the layer:
    expected ndim=3, found ndim=4. Full shape received: [None, 1, 4026, 5]</p>
  </blockquote>
  
  <p>I've tried various combinations of messing with the <code>input_shape</code> and have came to the conclusion, I have no idea how to determine the input shape.</p>
  
  <pre><code>model = Sequential()
  model.add(LSTM(32, input_shape=(1, x_train.shape[0], x_train.shape[1])))
  
  model.compile(optimizer='adam', loss='mse', metrics=['accuracy'])
  model.fit(x_train, y_train, epochs=10)
  </code></pre>
  
  <p>Given my dataframe, what should be my <code>input_shape</code>? I understand that the input shape is <code>batch size</code>, <code>timesteps</code>, <code>data dim</code>. Just not clear how to map those words to my actual data as what I've thought the values were, are actually not.</p>
  
  <p>I was thinking:</p>
  
  <ul>
  <li><strong>Batch Size</strong>: Number of records I'm passing in (4026)</li>
  <li><strong>Time Steps</strong>: 1 (I'm not sure if this is supposed to be the same value as batch size?)</li>
  <li><strong>Data Dimension</strong>: 1 since my data is 1 dimensional (I think?)</li>
  </ul>