Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Pytorch LSTM Example — Time Series Forecasting

Applying an LSTM Network to Forecast Time Series Data

Rian Dolphin
Level Up Coding

--

Image by Author

In this post, I will apply a long short-term memory (LSTM) network using PyTorch to forecast a time-series multiple periods into the future. Many time series exhibit seasonal trends as we can see on the graph above. For example, a company's sales may spike around the holiday season each year. This is characteristic of many retailers, from large companies to your local Sunday market, whose sales pick up due to the Christmas season.

These seasonal trends can be very tricky for a traditional model to pick up on but LSTMs have shown themselves to handle this type of problem quite well! The model itself will be quite basic; we will use the previous sixteen quarterly values to predict the following eight quarterly values. As such, we are essentially dealing with a time series forecasting problem.

The Data

The data is characteristic of any seasonal time-series data, with certain repeated patterns. The data is available, along with the code, on my Github here. Revenue data as used in this article is publically available for every public company through their legally required corporate filings, the data can be sourced here.

--

--