Handling trend – taking first differences
In Chapter 1, we learned about different time series patterns such as trend or seasonality. This recipe describes the process of dealing with trend in time series before training a deep neural network.
Getting ready
As we learned in Chapter 1, trend is the long-term change in the time series. When the average value of the time series changes, this means that the data is not stationary. Non-stationary time series are more difficult to model, so it’s important to transform the data into a stationary series.
Trend is usually removed from the time series by taking the first differences until the data becomes stationary.
First, let’s start by splitting the time series into training and testing sets:
from sklearn.model_selection import train_test_split train, test = train_test_split(series, test_size=0.2, shuffle=False)
We leave the last 20% of observations for testing.
How to do it…
There are two...