An introduction to time series forecasting
This article was originally published at Algorithimia’s website. The company was acquired by DataRobot in 2021. This article may not be entirely up-to-date or refer to products and offerings no longer in existence. Find out more about DataRobot MLOps here.
Despite its almost ubiquitous use in the business industry and social sciences, time series analysis and by extension time series forecasting is one of the least understood machine learning methods new data scientists and machine learning engineers are undertaking.
The purpose of this blog is to provide an overview of this lesser-known but incredibly important machine learning technique.
What is time series data?
To answer this question, let’s take a step back to discuss the types of data that we use for typical regression and classification tasks. When we make a prediction about a new observation, that model is built from hundreds or thousands of previous observations that are either all captured at a single point in time, or from data points in which time does not matter. This is known as cross-sectional data.
Time series data is different because it is recorded at regular time intervals, and the order of these data points is important. Therefore, any predictive model based on time series data will have time as an independent variable. The output of a model would be the predicted value or classification at a specific time.
What is a time series problem?
Here are a few examples of how different industries use time series forecasting:
- Energy – Prices; demand; production schedules
- Retail – Sales; consumer demand for certain products
- State government – Sales tax receipts
- Transportation – Demand for future travel
- Finance – Stocks; market potential
Time series analysis vs time series forecasting
This blog is focused on time series forecasting, but let’s clear up some possible confusion about the term time series analysis. While time series forecasting is a form of predictive modeling, time series analysis is a form of descriptive modeling. This means that someone conducting time series analysis is looking at a dataset to identify trends and seasonal patterns and associate them to external circumstances. Many social scientists and policy makers use this form of descriptive modeling to develop programs and recommendations.
The goal of time series forecasting however, is to predict a future value or classification at a particular point in time.
The four components of a time series
The first step in analyzing a time series in order to develop a predictive model is to identify and understand the underlying pattern of the data over time. These underlying patterns are usually classified as the following four components:
- Trend – The long-term gradual change in the series. This is the simplest trend pattern, as it demonstrates long-term growth or decline.
- Seasonality – Predictable, short-term patterns that occur within a single unit of time and repeat indefinitely.
- Cyclical component – Long-term swings in the data that may take years or decades to play out. These swings do not happen in a predictable manner and are often the result of external economic conditions.
- Noise (error) – Random variation due to uncontrolled circumstances.
What are time series forecasting methods?
The following are machine learning forecasting methods to use with time series data. When deciding on a method to use, keep the following in mind:
- Underlying assumptions about the data (ie. does the error follow a normal distribution?)
- The external factors that may influence the trend
- If the problem you’re trying to solve has a simple or complicated possible solutions
Simple time series forecasting methods
It’s possible that the most accurate machine learning time series forecasting model is the simplest. In the same way that data scientists often begin their modeling of cross-sectional data with simple linear regression, there are time series equivalents. Here are a few examples:
- Naive forecast – In a naive forecast the predicted value is simply the value of the most recent observation. This very basic method is often used as a benchmark to evaluate the performance of more sophisticated forecasts. In other words, if your complicated model is less accurate than the naive forecast, then you are likely doing something wrong.
- Average – In the average method, all forecasts are equal to the mean of all of the historical data.
- Seasonal naive method – This is similar to the naive forecast except that the predicted value is the last observed value from the same season of the time period. For example, on a monthly scale using this method, a November forecast would be equal to the last observed value in November.
Regression-based time series forecasting
You can develop linear, polynomial, and exponential regression time series forecasting models by creating a time index variable starting with the first observation (t=1) to the most recent (t=n). The result is a model of trend, but not seasonality. This is a useful method if your underlying assumption is that this trend is appropriate and relevant for your chosen time period.
If your model does need to take seasonality into account, that can also be done with linear regression. This is done by creating a categorical variable that indicates seasons.
Unlike regression models that are based on assumptions about trend or noise structure, time series smoothing methods are designed to adapt to changes in the data over time. Smoothing reduces noise by taking averages of observations over multiple periods. We discuss the two most common smoothing methods, moving average and exponential smoothing below:
Moving average – The moving average method generates a series of averages by taking the mean of values in the time series within designated periods. It is presumed that observations that close in time are probably also similar in value, so taking an average eliminates the noise. Moving averages are usually taken of the most recent data points.
Exponential smoothing – Exponential smoothing takes a weighted average over all past values, giving more weight to the most recent observations. The purpose is to acknowledge older information, while prioritizing the most recent data.
Special considerations for time series data
As you may know, developing a model requires dividing data into training and validation sets. With cross-sectional data, you would randomly divide the data into these groups. However, you can’t randomly divide data that has a sequential time element. For time series modeling, earlier data is used as the training set, while newer data is used as the validation set.
In addition, when forecasting new values the model itself is based on the entire data set, not just the training partition. This is because the data most relevant to a forecast are the observations that happened most recently.
Developing your own time series model
The process of developing your own time series machine learning model, is similar to how you would develop a model using cross-sectional data. We’ve detailed this process, but in short, here are the steps:
- Find a problem to solve or a question to answer
- Gather the data necessary to be able to answer the question
- Perform exploratory analysis
- Choose and test out models
- Evaluate the accuracy of your chosen model.
If you’re unsure where to start, check out this introductory post as well as the time series datasets found on Kaggle and the UCI Machine Learning Repository. Both have dozens of datasets specific to this machine learning technique.
DataRobot is the leader in Value-Driven AI – a unique and collaborative approach to AI that combines our open AI platform, deep AI expertise and broad use-case implementation to improve how customers run, grow and optimize their business. The DataRobot AI Platform is the only complete AI lifecycle platform that interoperates with your existing investments in data, applications and business processes, and can be deployed on-prem or in any cloud environment. DataRobot and our partners have a decade of world-class AI expertise collaborating with AI teams (data scientists, business and IT), removing common blockers and developing best practices to successfully navigate projects that result in faster time to value, increased revenue and reduced costs. DataRobot customers include 40% of the Fortune 50, 8 of top 10 US banks, 7 of the top 10 pharmaceutical companies, 7 of the top 10 telcos, 5 of top 10 global manufacturers.
We will contact you shortly
We’re almost there! These are the next steps:
- Look out for an email from DataRobot with a subject line: Your Subscription Confirmation.
- Click the confirmation link to approve your consent.
- Done! You have now opted to receive communications about DataRobot’s products and services.
Didn’t receive the email? Please make sure to check your spam or junk folders.
Accelerate Your AI Journey with the DataRobot Partner EcosystemMarch 28, 2023· 3 min read
How MLOps Enables Machine Learning Production at ScaleMarch 23, 2023· 4 min read
A New Era of Value-Driven AIMarch 16, 2023· 2 min read
Guest post by Dr. Chris Marshall, Associate Vice President, Big Data and Analytics, Cognitive Computing, IDC Asia/Pacific Heraclitus, the ancient Greek philosopher, noted that change is the only constant in the universe. Seers and prophets since the beginning of time have tried to pull back the curtain of the future based on omens, their insights and experience, and since the…
Learn how to improve time series forecasting when solving problems such as demand forecasting, staffing, inventory management, and more.
The DataRobot Automated Time Series product has traditionally been built on a supervised machine learning workflow, which allows users to forecast future events by specifying a target variable to train on. However, there are cases in which we would like to infer information from time series data without knowing the target. This may be in the form of detecting a…