Im having trouble sorting my data into the correct format for RNN with Keras. I have a csv file with 22 columns, 1344 rows. My data is continuous variables recorded at 30min intervals, over a number of weeks.
i understand that keras requires input in the format (num samples, timesteps, nfeatures) So for my data i saw this as (1344,48,22) (as there are 48 readings in a 24hr period in my data).
the x data is in the shape (1344,22) when imported from csv.
here is my code:
model=Sequential()
model.add(LSTM(21, input_shape=(1344,22),kernel_initializer='normal',activation='relu',return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(19, activation='relu')) #hidden layer 2
model.add(Dropout(0.2))
model.add(Dense(8, activation='relu')) #output layer
model.compile(loss='mean_squared_error', optimizer=optimiser,metrics=['accuracy','mse'])
which resulted in the error Error when checking input: expected lstm_1_input to have 3 dimensions, but got array with shape (1344, 22)
I tried to make the x data into the correct data by adding a embedding layer. my code now reads:
model=Sequential()
model.add(Embedding(input_dim=22,input_length=1344,output_dim=48))
model.add(LSTM(21, input_shape=(1344,22), kernel_initializer='normal',activation='relu',return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(19, activation='relu')) #hidden layer 2
model.add(Dropout(0.2))
model.add(Dense(8, activation='relu')) #output layer
model.compile(loss='mean_squared_error', optimizer=optimiser,metrics=['accuracy','mse'])
history=model.fit(x,y, verbose=0,epochs=150, batch_size=70, validation_split=0.2)
resulting in the error: Error when checking input: expected embedding_1_input to have shape (1344,) but got array with shape (22,).
im not sure i have fully understood the embedding layer or the meanings of (num samples. timesteps, nfeatures). could someone explain the meanings of input_dim, input_length and output_dim with reference to my data? ive read many other posts on this issue and cant seem to fix the issue applying the problem to my data type!
many thanks for your help.