How to Make a Good “Trend” and “Seasonality” Forecasting

Beny Maulana Achsan
IT Paragon
Published in
4 min readJan 25, 2020

Discussing time series forecasting, there are three types of time series patterns: trend, seasonal, and cyclic. In this case, we just discuss the trend and seasonal patterns. A trend pattern exists when there is a long-term decrease or increase in the time series. The trend can be linear or non-linear, such as an exponential function. In another hand, seasonal pattern exists when the data is influenced by seasonal factors, such as a day of the week, a month, or two-quarter of the year. In other words, a seasonal pattern exists of a fixed known period.

Regression

Based on what we’ve discussed before, regression is one of the main tasks in supervised machine learning. You need some input and your target variable is a single floating-point number. For example, predicting the world gold price. A big difference between regression and classification is its targets. The targets in regression are just a few infinite ones, while you have finite possible targets for classification.

Elastic Net vs Extra Trees Regression

Elastic Net Regression first emerged as a result of critique on the lasso regression, whose variable selection can be too dependent on data and thus unstable. The solution is to combine the penalties of ridge regression and lasso regression to get the best of both. For further explanation, you can read it on web.standford.edu. In this case, we use the international airline passenger’s history from 1949 to 1960 as the data set (80% as data train and 20% as data test).

Figure 1: Elastic Net Regression Model

Extra Trees Regression also known as Extremely Randomized Trees is a meta estimator that fits several randomized decision trees on various sub-samples of the data set and uses averaging to control over-fitting and improve the predictive accuracy.

Figure 2: Extra Trees Regression Model

Seeing the two above modeling, we can decide to have two models: One which predicts the trend (Figure 1) and another one which predicts seasonality effects (Figure 2). Based on the two models above, can we have a good “trend” and “seasonality” forecasting? The answer you can find in the following section.

Combining The Models

To make a good “trend” and “seasonality” forecasting, we can combine Elastic Net Regression with Extra Trees Regression. The following are the steps to combine it.

1. Assume we have a function f(x):

f(x) = f1(x) + f2(x)

where f1(x) is Elastic Net Regression Function and f2(x) is Extra Trees Regression Function.

2. Fit f1(x) on the training data set, where f1(x) has to predict the global trend and thus solve the extrapolation problem.

3. Transform the training data set (x, y):

y′ = y − f1(x)

4. Fit f2(x) on (x, y′). So f2(x) has to solve an interpolation problem.

Figure 3: Combining Elastic Net with Extra Trees Regression Model

Plotting the prediction is crucial for extrapolation. What we can see in the above image (Figure 3) is that there are two things to match: A global trend and local seasonality-effects. Below, you can see a list of scoring functions by using MAE.

Figure 4: Scoring Function of Elastic Net, Extra Trees, and Elastic Net & Extra Trees Regression Model

Conclusion

MAE tells us how many the airline passengers prediction is typically away from the true value. The small MAE value means good prediction and vice versa. Please note that the high MAE value here do not mean the regression model is bad. Some might be better when use more data set, some might be better suited to different regression problems, e.g. extrapolation instead of interpolation or working with higher dimensional data. Thank you for reading this article and have a nice weekend :)

--

--