Keras/Tensorflow Error: Specified a list with shape [3,1] from a tensor with shape [32,1]

I have been experimenting with keras/tensorflow to build up my confidence and am currently trying to build a LSTM model that forecast the price of a stock based on the price of the stock in the previous ten days. Lets start by saying that the results were terrible in the beginning (the model was predicting an almost constant value with a mae of 20%. I've identified the culprit (or so I think) of such underperformance in the batch size, I would like to train the model with very small batches, however, if I try the argument batch_input_shape in the first LSTM layer it gives me this weird error:

Specified a list with shape [3,1] from a tensor with shape [32,1]. here's the code:

df = df_manupulation.returnStockDf(timeSeriesLenght=10) #returns a df with shape 1344 x 11 (10 inputs, one output)
print(df.shape)
input_array = df.drop(columns='Y').to_numpy() #retains all first 10 columns
output_array = df['Y'].to_numpy()

X_train, X_test, y_train, y_test = train_test_split(input_array, output_array, train_size=999, shuffle=False)

model = Sequential()
model.add(LSTM(128, activation='relu', return_sequences=True, batch_input_shape= (3,10,1)))
model.add(LSTM(64, activation='relu', return_sequences=False, dropout =0.2))
model.add(Dense(15,activation='relu'))
model.add(Dense(1))

model.compile(optimizer='adam',
              loss='mse',
              metrics = ['mape'])
model.fit(X_train, y_train, epochs=50, validation_data=(X_test,y_test), verbose=1)

I couldn't find anything else that could help solving this issue, anyone more experienced is kind enough to help out on this one?

EDIT: the only parameter that works as a first parameter of batch_input_shape is 32, if I set anything higher or lower than that it will always give me the same error

Topic cnn lstm keras tensorflow

Category Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.