Univariate forecasting with a GRU
This recipe walks you through the process of building a GRU neural network for forecasting with univariate time series.
Getting ready
Now that we have seen how LSTMs can be used for univariate time series forecasting, let’s now shift our attention to another type of RNN architecture known as GRU. GRUs, like LSTMs, are designed to capture long-term dependencies in sequence data effectively but do so with a slightly different and less complex internal structure. This often makes them faster to train.
For this section, we will use the same training and testing sets as in the previous sections. Again, the input data should be reshaped into a 3D
tensor with dimensions representing observations, time steps, and features respectively:
X_train = X_train.view([X_train.shape[0], X_train.shape[1], 1]) X_test = X_test.view([X_test.shape[0], X_test.shape[1], 1])
How to do it…
Let’s start constructing a GRU network with the...