How to Prepare the Input-set for LSTM Multivariate Time Series Sequence to Sequence Predictions

Caner
1 min readMar 30, 2020

--

If you are dealing with the multivariate time-series data to predict the values for next 10 hours then you need to be very careful especially when you are configuring the inputs data sets to train the LSTM model as well to test and validate the model performance.

Here below I demonstrate how to suppose to configure the inputs in order to help you to prepare the input datasets based on selected timesteps value as described here.

X_train = []
y_train = []
# Creating a data structure with n timesteps which is 10 in our example
print(train_size + timesteps)
for i in range(timesteps, train_size + timesteps):
X_train.append(X_train_set[i-timesteps:i,:])
y_train.append(y_train_set[i:i+timesteps])
print(“len(X_train)”,len(X_train))
print(“len(y_train)”,len(y_train))
#create X_train matrix
#10 items per array (timestep)
print(“np.array(X_train).shape=”,np.array(X_train).shape)
print(“X_train[1].shapee=”,X_train[1].shape)
#create Y_train matrix
#10 items per array (as much as timestep)
print(“y_train[0:2]”,y_train[0:2])
print(“np.array(y_train).shape=”,np.array(y_train).shape)
print(“############################”)
print(“############################”)
print(“############################”)
# Do the same for your test data
X_test = []
y_test = []
# Creating a data structure with n timesteps
print(test_size + timesteps)
for i in range(timesteps, test_size + timesteps):
X_test.append(X_test_set[i-timesteps:i,:])
y_test.append(y_test_set[i:i+timesteps])
print(“len(X_test)=”,len(X_test))
print(“len(y_test)=”,len(y_test))
#create X_test matrix
#10 items per array (timestep)
print(“np.array(X_test).shape=”,np.array(X_test).shape)
print(“X_test[1].shape=”,X_test[1].shape)
#10 items per array (timestep)
print(“y_test[0:2]”,y_test[0:2])
print(“np.array(y_test).shape=”,np.array(y_test).shape)

--

--