Time series Forecasting in Machine Learning
“Detecting Timely Patterns in Data”
Understanding timely patterns/characteristics in data are becoming very critical aspect in analyzing and describing trends in business data .
Example Use case 1 : Fitness device market is built around buy people to help track fitness related data to monitor effectiveness of their fitness exercises.
Example Use Case 2 : Sales growth of a product over period of time is a good indicator of sales performance of a product manufacturing company.
Common Time Series Patterns
A typical time series model can exhibits different patterns.
in most of the situation it can be a graph of a combination of all of above patterns . Therefor it is important to understand components of a time series in detail . Next section will describe the detail component of a time series .
Components of a time series
A time series can be analyze in detail by breaking down it into its primary components . We call this process as time series decomposition . If you closely look at a time series it is composed of Trend , Seasonality, Cyclic and Residual components.
- Trend Component
The long-term tendency of a series to increase or fall (upward trend or downward trend).
2. Seasonality Component
The periodic fluctuation in the time series within a certain period. These fluctuations form a pattern that tends to repeat from one seasonal period to the next one.
3. Cycles Component
Long departures from the trend due to factors others than seasonality. Cycles usually occur along a large time interval, and the lengths of time between successive peaks or troughs of a cycle are not necessarily the same.
4. Irregular movement Component
The movement left after explaining the trend, seasonal and cyclical movements; random noise or error in a time series.
Modeling a time series using R
For the demonstration purpose i have used a time series use case from banking industry as explained below.
Business Case : How do you predict the remaining balance of bank account for remaining two years.
- Financial expenditures of a bank users are highly unpredictable over the period of time.
- Expenditure patterns of the user is random in nature.
When the behavioral pattern of a user unknown and random in nature there is no easy way that you can write a business logic to automatically predict the future balances in the user account .
Solution : Use a machine learning approach to create a prediction model predict future account balances of the user .
Lets use step by step approach go trough a practical time series use case .
Step 0
In this case i am using a CSV file which has monthly balance of the users bank account starting from 1973–01 to 2013–06 .
Step 1: install forcast and fpp packages in R Studio
Step 2: Load data from CSV file into R data frame .
Step 3: create time series Object using “AccountBal” data frame.
Step 4: plot time series Object .
step 5 : Decomposing time series into its components
you can use decompose command to split the time series into its trend , seasonal and irregular components
step 6 : Predicting remaining balances of account for next 10 years using holtWinter Prediction Model.
Prediction is done in two steps . In first step you create the holtWinters model by using past time series data . Then in the second step we use that model to make predictions for next 10 years .
Then you can pot the predicted values in a new time series graph from 2014–2022
As the final step you can decompose the predicted time series to identify future trends and future seasonal effects reaming account balance of the user .
As a summery in this article i have tried to give you a basic understanding about the time series modeling . In future articles i may discuss some advance concepts around time series modeling subject area.