title: LSTM input_shape in keras
body: <p>I am implementing a LSTM network in keras Spyder according to a Udemy tutorial. In the tutorial video the code is running but when I run it on my own, which step by step is precisely implemented the same as the tutorial video code, it gets an error which is:</p>
  
  <blockquote>
    <p>Error when checking target: expected dense_26 to have 3 dimensions, but got array with shape (1198, 1)</p>
  </blockquote>
  
  <p>Does it relate to the version of Spyder? The size of <code>x_train</code> is <code>(1198,60,1)</code> and <code>y_train</code> size is <code>(1198,)</code>  </p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  import pandas as pd
  
  #Importing the training set
  dataset_train = pd.read_csv('E:\\downloads_1\\Recurrent_Neural_Networks\\Google_Stock_Price_Train.csv')
  training_set = dataset_train.iloc[:,1:2].values
  #Feature Scaling 
  from sklearn.preprocessing import MinMaxScaler
  sc = MinMaxScaler(feature_range=(0,1))
  training_set_scaled = sc.fit_transform(training_set)
  #Creating a Data Structure with 60 timesteps and 1 output
  x_train = []
  y_train = []
  for i in range(60,1258):
      x_train.append(training_set_scaled[i-60:i , 0])
      y_train.append(training_set_scaled[i , 0])
  x_train , y_train = np.array(x_train) , np.array(y_train)
  
  #Reshaping
  x_train = np.reshape(x_train , (x_train.shape[0],x_train.shape[1], 1))
  
  
  
  #Part 2_Building the Rnn
  
  #importing te keras Libraries and Packages
  from keras.models import Sequential
  from keras.layers import Dense
  from keras.layers import Dropout
  from keras.layers import LSTM
  
  
  #initializing the RNN
  regressor = Sequential()
  
  #Adding the first layer LSTM and some Dropout Regularisations
  regressor.add(LSTM(units = 50, return_sequences= True, input_shape = (x_train.shape[1], 1)))
  regressor.add(Dropout(0.2))
  
  #Adding the second layer LSTM and some Dropout Regularisations
  regressor.add(LSTM(units = 50, return_sequences= True))
  regressor.add(Dropout(0.2))
  
  #Adding the third layer LSTM and some Dropout Regularisations
  regressor.add(LSTM(units = 50, return_sequences= True))
  regressor.add(Dropout(0.2))
  
  #Adding the fourth layer LSTM and some Dropout Regularisations
  regressor.add(LSTM(units = 50, return_sequences= True))
  regressor.add(Dropout(0.2))
  
  #Adding the output layer
  regressor.add(Dense(units = 1))
  
  #compiling the RNN
  regressor.compile(optimizer= 'adam',  loss = 'mean_squared_error')
  
  #Fitting the RNN TO the training set`enter code here`
  regressor.fit(x_train, y_train, epochs = '100', batch_size = 32 )
  </code></pre>