# How to implement an LSTM RNN with multiple input features

EDIT: Now I didn't convert to list.

I am training LSTM for multiple time-series in an array which has a structure: 450x801. There are 450 time series with each of 801 timesteps / time series. The labels are classes with assigned integer from 1 to 6, so the dimension of the label is 450x1. This is my implmentation:

This is my code:

def readData():
labels = labels.values
return data, labels

data_train, data_test, labels_train, labels_test = train_test_split(data, labels)

model = Sequential()


Now I got this error:

Error when checking input: expected lstm_26_input to have 3 dimensions, but got array with shape (450, 801)


Any idea how to solve it?

For instance I can try to reshape:

data_train = np.reshape(data_train, (data_train.shape[0], 1, data_train.shape[1]))
data_test = np.reshape(data_test, (data_test.shape[0], 1, data_test.shape[1]))


And now the error is:

raise ValueError('Must pass 2-d input') ValueError: Must pass 2-d input

• Please correct me if I'm wrong. You are trying a classification task with a multivariate LSTM model that takes 450 variables as input? – Leevo Sep 16 '19 at 8:38
• @Leevo, yes, that's correct. Wouldn't it work? – user2754279 Sep 17 '19 at 10:00
• It can work, but the computational effort is going to be huge – Leevo Sep 17 '19 at 10:12

I spot an error in your code. The input sequence for LSTM() layers must follow this schema:

( Number of observations , Number of Timesteps , Number of input series )

When you specify the input_shape argument you drop the number of observations. Therefore it becomes:

model = Sequential([

LSTM(32, input_shape = (801, 450)),

Dense(6, activation='softmax')
])


It is becouse you convert your data to list data = data.values.tolist() But model input expects an array but not a list of arrays. So you need to convert your input list to the array.