 # Creating the Dataset

In this exercise, we are going to use GRU, which is one of the quite useful deep learning algorithms to deal with time-series data.

It expects the input data to be three-dimensional. The first dimension indicates the batch size, the second dimension is the timestamps and the third dimension is the number of features.

Let us feed 2 values to predict the next value. To create the data set, let us define the `create_dataset` function.

In the function, we will be traversing till the last third row of the dataset, combine every two consecutive values as one input, and put the third value as the value to be predicted(ground truth of prediction).

INSTRUCTIONS
• Copy-paste the following function to create the dataset.

``````def create_dataset(data , n_features):
dataX, dataY = [], []
for i in range(len(data)-n_features-1):
a = data[i:(i+n_features), 0]
dataX.append(a)
dataY.append(data[i + n_features, 0])
return np.array(dataX), np.array(dataY)
``````
• Set `n_features` value to 2.

``````n_features = 2
``````
• Pass the `train` , `val` and `test` to create the datasets for each, by passing them as arguments to the `create_dataset` function.

``````trainX, trainY = << your code comes here >>(train, n_features)
valX, valY = create_dataset(<< your code comes here >>, n_features)
testX, testY = create_dataset(<< your code comes here >>, n_features)
``````
• Let us have a look at the shape of `trainX`,`trainY`, `valX`,`valY`, `testX`, `testY`.

``````print(trainX.shape , trainY.shape , valX.shape , valY.shape, testX.shape , testY.shape)
``````
• Now, reshape `trainX`,`valX`, `testX` into the required three-dimensional shape, where first argument is the number of rows of that dataset, second argument is 1 and third argument is number of features which is the number of columns of the dataset.

``````trainX = trainX.reshape(trainX.shape , 1 ,trainX.shape)
valX = valX.reshape(valX.shape , 1 ,valX.shape)
testX = testX.reshape(testX.shape , 1 ,testX.shape)
``````
• Now print the shape of `trainX`,`trainY`, `valX`,`valY`, `testX`, `testY`.

``````print(trainX.shape , trainY.shape , valX.shape , valY.shape, testX.shape , testY.shape)
``````

No hints are availble for this assesment

Answer is not availble for this assesment

Note - Having trouble with the assessment engine? Follow the steps listed here