Univariate forecasting with a CNN
Now, we turn our attention to convolutional neural networks that have also shown promising results with time series data. Let’s learn how these methods can be used for univariate time series forecasting.
Getting ready
CNNs are commonly used in problems involving images, but they can also be applied to time series forecasting tasks. By treating time series data as a “sequence image,” CNNs can extract local features and dependencies from the data. To implement this, we’ll need to prepare our time series data similarly to how we did for LSTM models.
How to do it…
Let’s define a simple CNN model in PyTorch. For this example, we will use a single convolutional layer followed by a fully connected layer:
class CNNTimeseries(nn.Module): def __init__(self, input_dim, output_dim=1): super(CNNTimeseries, self).__init__() ...