1.1. Time-series & forecasting models
Traditionally most machine learning (ML) models use as input features some observations (samples/examples), but there is no time dimension in the data.
Time-series forecasting models are the models that are capable of predicting future values based on previously observed values. Time-series forecasting is widely used for non-stationary data. Non-stationary data are called the data whose statistical properties, e.g., the mean and standard deviation, are not constant over time but instead, these metrics vary over time.
These non-stationary input data (used as input to these models) are usually called time-series. Some examples of time-series include the temperature values over time, stock price over time, price of a house over time, etc. So, the input is a signal (time-series) that is defined by observations taken sequentially in time.
A time series is a sequence of observations taken sequentially in time.
Observation: Time-series data is recorded on a discrete time scale.
Disclaimer (before we move on): There have been attempts to predict stock prices using time series analysis algorithms, though they still cannot be used to place bets in the real market. This is just a tutorial article that does not intend in any way to “direct” people into buying stocks.
1.2 The forecasting model: Facebook’s Prophet
The most commonly used models for forecasting predictions are the autoregressive models. Briefly, the autoregressive model specifies that the output variable depends linearly on its own previous values and on a stochastic term (an imperfectly predictable term).
Recently, in an attempt to develop a model that could capture seasonality in time-series data, Facebook developed the famous Prophet model that is publicly available for everyone. In this article, we will use this state-of-the-art model: the Prophet model. Prophet is able to capture daily, weekly and yearly seasonality along with holiday effects by implementing additive regression models.
The mathematical equation behind the Prophet model is defined as:
y(t) = g(t) + s(t) + h(t) + e(t)
- with, g(t) representing the trend. Prophet uses a piecewise linear model for trend forecasting.
- s(t) represents periodic changes (weekly, monthly, yearly).
- h(t) represents the effects of holidays (recall: Holidays impact businesses).
- e(t) is the error term.
The Prophet model fitting procedure is usually very fast (even for thousands of observations) and it does not require any data pre-processing. It also deals with missing data and outliers.
In this article, we are going to use the Prophet mode to predict Google’s stock price in the future.
Let’s get started!