# Classical Time Series Forecasting Using Python

Time Series is generally data that is collected over time and is dependent on it. It is simply a series of data points ordered in time.

Components of a Time Series

1) Trend We can define change as a general direction in which a specific thing develops or changes. A trend can be increasing or decreasing. Example: We can see an increasing trend in the population of India over time.

2) Seasonality The repetition of a pattern at regular intervals of time is called Seasonality.

### General Approach to Time Series

1) Hypothesis Generation This is done before taking a look at the data. We generate a hypothesis based on all the previous knowledge we have about the data. This helps in generalization about which variables will really affect the forecast and how will it affect.

2) Data Analysis and Hypothesis Verification We now explore the data, analyze it and check whether our hypothesis holds true based on our analysis.

3) Forecasting We now have a hypothesis and we have analyzed the data. We will now move on to the forecasting using various methods.

### Forecasting using various statistical methods

1) AutoRegressive Model(AR) It is a time series model that uses observations from previous time steps as input to make predictions for the future. The autoregressive model specifies that the output variable depends linearly on its own previous values.

2) Moving Average Model(MA) Rather than using past values of the forecast variable in a regression, a moving average model uses past forecast errors in a regression-like model. yt=c+εt+θ1εt−1+θ2εt−2+⋯+θqεt−q, where εt is white noise. We refer to this as an MA(q) model, a moving average model of order q. Of course, we do not observe the values of εt, so it is not really a regression in the usual sense.

3) Simple Exponential Smoothing(SES) Single Exponential Smoothing, SES for short, also called Simple Exponential Smoothing, is a time series forecasting method for univariate data without a trend or seasonality.

4) AutoRegressive Integrated Moving Average Model(ARIMA) In statistics and econometrics, and in particular in time series analysis, an autoregressive integrated moving average (ARIMA) model is a generalization of an autoregressive moving average (ARMA) model. Both of these models are fitted to time series data either to better understand the data or to predict future points in the series (forecasting). ARIMA models are applied in some cases where data show evidence of non-stationarity, where an initial differencing step (corresponding to the “integrated” part of the model) can be applied one or more times to eliminate the non-stationarity.

Get the code and data used in the above article GitHub

Now we’ll see the implementation of these models on a Time Series Data using Python

### 2) AutoRegressive Model(AR):

#### General equation for this model would be Y(t) = b0 + b1Y(t-1) + b2Y(t-2) + ….

It works well when there is high correlation between past and current values

### 5) ARIMA:

It is specified by three ordered parameters (p,d,q):

• p: the order of the autoregressive model(number of time lags).
• d: the degree of differencing(number of times the data has had past values subtracted).
• q: the order of moving average model. We will discuss more about these parameters in next section.