Time Series forecasting is a very important area of machine learning, because there are a lot of prediction tasks that involve a time component. Examples are the prediction of a stocks closing price or forecasting a companies sales. After reading this post you will know about the basic concepts of Time Series Forecasting and how a business takes advantage of it.
Table of Contents:
- What is Time Series Forecasting ?
- What is a Time Series ?
- Why Order Matters
- How is it used ?
- Simple Forecasting Methods
- Time Series Plots
- Seasonality Plots
- Cyclical Patterns
- What is Time Series Forecasting ?
Time Series Forecasting is an important area of machine learning with the goal to predict things that involve a time component. It is often neglected, because the involved time component makes it a bit harder. It basically allows us to forecast any variable that can be tracked and collected over time. Examples are a stocks closing price, annual population data or sales figures. A Time Series Forecasting model is just using the collected data to forecast future values.
What is a Time Series ?
A time series is a series of data points that are listed in time order. It is a sequence of data points that covers a continuous time interval. A Time Series has equal spacing between two measurements that follow each other. Each time-unit, within the time interval, has mostly one data point.
Why Order Matters
Correct Ordering within a Time Series is very important, because their is a dependency on time. If the order is changed, it could change the meaning of the data. To predict future values, each data measurement must be taken across sequential and equal intervals, where each time unit has at most one data point.
How is it used ?
To better explain how a company uses and benefits from Time Series forecasting methods, we will go through an example of the European drug store company Rossmann. Rossmann uses Time Series Forecasting to predict sales using store, promotion, and competitor data that enable their store managers to create effective staff schedules that increase productivity and motivation. This helps store managers stay focused on what’s most important to them: their customers and their teams!
Their Data Scientists and Machine Learning engineers work along with a dataset that contains data from the last few years. Once the data is collected, they have two objectives in mind. First, they need to identify patterns and trends within the sequence of the data and second, they need to predict the future values of the time series. They investigate and clean the data, then they determine trends and seasonal components. Afterwards they apply it to a Time Series tool like ARIMA or ETS, to forecast the Sales for the next weeks and use these within their planning.
Simple Forecasting Methods
There are a few simple forecasting methods, that didn’t use any machine learning, which we should talk about, before we continue going deeper into the topic. Of course these simple methods have their faults and are only occasionally effective.
The first method is the average method. Here the forecast is simply the average of all our previous data. The model assumes that the best predictor of what will happen tomorrow is the average of everything that has happened up until now.
The second method is the moving average method. Here the method uses the average of a given time series over a defined number of periods.
The third method is the Naive method, where you just use the value of the last observation as a forecast for the next one. If you have not enough data to build a predictive model, these methods can supplement rough forecasts for the near future.There is also the seasonal naive method that assumes the magnitude of the seasonal pattern will remain constant.
Time Series Plots
A time series plot shows a graphical presentation of the relationship between the data and time.The Time is displayed on the horizontal axis and the target variables values are shown on the vertical access. Plotting out the time series allows us to spot patterns and behaviors, that might stay undetected without it. The insights we gained from visualizing our Time Series can then be used to fine-tune sophisticated forecasting models.
A trend is a movement to relatively higher highs or lower lows over a long period of time. Higher highs that follow higher lows are defined as a uptrend, while lower lows followed by lower highs define a downtrend. If the movement doesn’t really produced any higher highs or lower lows we call that a horizontal trend. If we have for example a uptrend, statistically the trend is more likely to continue.
Let’s explain this further with an example. If a company continuously acquires new costumers that spend money on their products, they would experience an uptrend. In the opposite case, they would experience a downtrend. During the shift from the upward to the downward trend, the number of costumer is remaining nearly the same, which results in a horizontal trend.
A Time Series that shows a repeating pattern at fixed intervals of time, within a one year period, is called a seasonal pattern or seasonality. Seasonal patterns can be spotted across many kinds of time series. A example is that your heating costs reduce in the summer and rise in the winter. Companies need to understand seasonality to properly manage their inventory, staff and many other important things.
A seasonality plot is a good way to spot seasonal patterns through visual observation. Let’s take a look at the picture below, which is a seasonality plot of a hotel. On the vertical axes, you can see the number of bookings the hotel received and at the horizontal axes, you can see the months in chronological order. You can see that the results between summer and winter months are significantly different. A reason for that is probably that many people want to go skying in the winter months and therefore there are more sales in the winter. Because of that we can safely say that our time series contains seasonality.
Another thing that we can spot at the seasonality plot is that the number of bookings increases a little bit year after year.
A pattern within data that includes rises and falls that are not of a fixed period, is called a Cyclical pattern. So a pattern that doesn’t occur within the same calendar year, is probably a Cyclical pattern. These patterns last several years and don’t have a repeating pattern within each year.
Think of stock market cycles that last a few years where the length of a current cycle is unknown. In the world of stocks, a cyclical uptrend is called a bull market and a cyclical downtrend is called a bear market. Cyclical patterns are often times confused with seasonal patterns but be aware of the fact that they are quite different. Let’s go back to our stock market example. If the market fluctuations are not of a fixed period, they belong to cyclical behavior. If they do and if they are also associated with some aspects of the calendar, they belong to seasonal behavior.
Note that the average cyclical pattern last’s longer than the average seasonal pattern. Also the magnitude of cyclical patterns is likely to change more often then the ones of seasonal patterns. On top of that cyclical patterns are way harder to predict. Think of predicting a stock market crash, which is nearly impossible without insider information.