title: Keras LSTM batch input shape
body: <p>Hello I can not seem to figure out the relationship between the reshapping of X,Y with the batch input shape of Keras when dealing with a LSTM.</p>
  
  <p>current database is a 84119,190 pandas dataframe i am bringing in.  from there break out to X and Y.  so features is 189.  If you could point out where i am wrong as it relates to the (sequence, timestep, dimensions) it would be appreciated.  </p>
  
  <pre><code>import numpy as np
  import pandas as pd
  from keras.models import Sequential
  from keras.layers import LSTM    
  
  # load dataset
  training_data_df = pd.read_csv("C:/Users/####/python_folders/stock_folder/XYstore/Big_data22.csv")
  
  
  X = training_data_df.drop('Change Month End Stock Price', axis=1).values
  Y = training_data_df[['Change Month End Stock Price']].values
  
  
  data_dim = 189
  timesteps = 4
  numberofSequence = 1
  
  X=X.reshape(numberofSequence,timesteps,data_dim)
  Y=Y.reshape(numberofSequence,timesteps, 1)
  model = Sequential()
  model.add(LSTM(200, return_sequences=True,batch_input_shape=(timesteps,data_dim)))
  model.add(LSTM(200, return_sequences=True))  
  model.add(LSTM(100,return_sequences=True))  
  model.add(LSTM(1,return_sequences=False, activation='linear'))
  model.compile(loss='mse',
                optimizer='rmsprop',
                metrics=['accuracy'])
  model.fit(X,Y,epochs=100)
  </code></pre>
  
  <h1>Edit to fix issue</h1>
  
  <p>thanks to the help below.  Both helped me think through the problem.  still have some work to do to really understand it.  </p>
  
  <pre><code>import numpy as np
  import pandas as pd
  from keras.models import Sequential
  from keras.layers import LSTM
  
  
  
  
  training_data_df = pd.read_csv("C:/Users/TurnerJ/python_folders/stock_folder/XYstore/Big_data22.csv")
  
  training_data_df.replace(np.nan,value=0,inplace=True)
  training_data_df.replace(np.inf,value=0,inplace=True)
  training_data_df = training_data_df.loc[279:,:]
  X = training_data_df.drop('Change Month End Stock Price', axis=1).values
  Y = training_data_df[['Change Month End Stock Price']].values
  
  
  data_dim = 189
  timesteps = 1
  numberofSequence = 83840
  
  X=X.reshape(numberofSequence,timesteps,data_dim)
  Y=Y.reshape(numberofSequence,timesteps, 1)
  model = Sequential()
  model.add(LSTM(200, return_sequences=True,batch_input_shape=(32,timesteps,data_dim)))
  model.add(LSTM(200, return_sequences=True))  
  model.add(LSTM(100,return_sequences=True))  
  model.add(LSTM(1,return_sequences=True, activation='linear'))
  model.compile(loss='mse',
                optimizer='rmsprop',
                metrics=['accuracy'])
  
  
  model.fit(X,Y,epochs=100)
  </code></pre>