How to fix a common mistake in LSTM time series forecasting
When using LSTM for time series forecasting, people tend to fall into a common trap. To explain it we need to review how regressors and forecasers work. This is how a forecasting algorithm deals with a time series:
Meanwhile, a regression problem looks like this:
Because LSTM is a regressor, we need to transform our time series into a regression problem. There are numerous methods to do this, but in this section, we will discuss the Window and Multi-Step Methods, how they work, and particularly, how to avoid a common mistake in employing them.
In the Window Method, the time series is coupled with previous values of each time step as virtual features called the window. Here we have a window of size 3:
The following function creates a Window method data set from a single time series. The user should select the number of previous values (often called look back). The resulting data set will have diagonal repetition, and depending on the look-back value, the number of samples will vary:
def window(sequences, look_back):
X, y = [], []
for i in…