Reputation: 1065
I have pandas dataframe of length 7499042 like this:
'X' 'y'
[0.1,0.2...] 0.2
[0.3,0.4,..] 0.3
.
.
each value in pandas dataframe is numpy array of length 50. Now I am extracting it like this:
input = df['X'].values
I have layers like this:
main_input = Input(shape=(50,1), name='main_input')
lstm_out=LSTM(32,activation='tanh',recurrent_activation='sigmoid',return_sequences=True)
mean_pooling=AveragePooling1D(pool_size=2,strides=2,padding='valid')
But when I am passing my input to this while training. It is showing the error:
ValueError: Error when checking input: expected main_input to have 3 dimensions, but got array with shape (7499042, 1)
The shape of input it is showing is (7499042,). Please help me in resolving this.
Upvotes: 4
Views: 982
Reputation: 2121
You need to reshape your features before feeding them to the LSTM network. The LSTM layer takes a 3 dimensional input, corresponding to (batch_size, timesteps, features). This means that a single observation has to be two dimensional (timesteps, features)
In your case, a single observation is 1 dimensional (50 ,) : the whole dataset dimension is : (7499042 , 50) if the conversion was done correctly. You have to reshape your input before using it :
input = df['X'].values
input = input.reshape(input.shape[0] , input.shape[1] , 1)
in case Pandas didn't convert your initial feature to a 2d DataFrame, you have to do it before executing the above code.
Upvotes: 1