Time Series Analysis

Rekha V S
4 min readJan 17, 2021

Let’s first understand what is time series, it is collection of data which varies with time, may be increasing or decreasing with respect to time.A Time series is a series of data points indexed (or listed or graphed) in time order i.e. it is a sequence of discrete time data. Let’s look into example price of stock which may increase or decrease with time, sales of blanket, ice cream is dependent on certain seasons, these kind data which are related to time is consider as a Time Series data.

But why there is a need for this Time Series Analysis? Consider scenario of Hotel room booking during vacation, festival season bookings will be much higher than normal days, hence during such time the management should take of room availabilities, staffing etc.

Before proceeding further let us first understand important terminologies in Time Series :

1. TREND : It indicate pattern in the data.

In the above figure we can find some pattern with respect to time and price, in that we can figure out that with increase in time if price too gets increased then it is UPTREND, on the other hand if price decreases with respect to time then it is called as DOWNTREND.

2. SEASONALITY

When data exhibit repetitive pattern over an year it is known as seasonality. For example consider sales of Ice Cream which increases during summer than in winter this is known as seasonality.

3. CYCLIC PATTERN

This is similar to seasonal pattern but instead of an year this repetitive pattern occurs for every cycle of periods. For example, after every five year the share market has some fluctuations due to the general elections.

Let’s now solve time series problem

consider a problem of ice cream sales prediction using time series analysis, some of the old methods are Average, Moving Average, Naïve method, Seasonal Naïve method.

  1. Average : Average tells us the average sales of ice cream throughout the year. This is not such accurate because sales will be in the peak during summer, since it takes average winter season will also be covered, which affects the prediction results.
  2. Moving Average : This is similar to average method unlike taking entire data, window is consider. for example need to find sales of December, let us assume window size as 3, then sales will average of previous 3 months(September, October, November).
  3. Naïve Method: The Naïve method says that the prediction will be same as the last figure. For example, the prediction for November will be the sales for October.
  4. Seasonal Naïve Method: Seasonal naïve method is similar to naïve method. Here, the new prediction is equal to the sales for the previous season.

These old methods is limited to some extent hence we can see some modern methods of handling Time Series.

  1. ARIMA : where AR is Auto Regression, MA is Moving Average and I is differencing.

Before moving a step into AR let’s first try to recollect what is regression, In regression the target value is determined by combination of features. But in AR the new target value is determined by combination of old target value

While I is differencing, ARIMA is built in assumption that Time Series data should be stationary(i.e. it should not follow any trend in data). But most of data will have some patterns like uptrend, downtrend these data should be converted to stationary data before applying ARIMA model. But how this can be done? to solve this problem and to convert into a stationary data I is used.

Here in the above figure we can see that target is not stationary and it will surely follow some trend, to make it stationary we difference it with previous value(see d1), here too the values exhibit uptrend hence d2 is calculated now see(d2) all the values are equal hence it has now become stationary, we are now good to go with further analysis. Let’s now look into Auto Correlation(q)

Look into the above table, here we need to find Auto Correlation(ACF), by the way what is ACF? we know that correlation says how our features are correlated and auto means at the same column, combine these two definition i.e. ACF says how our values are correlated within the same target column.

In the below figure x-axis denotes sample value in the above table, first point 100, 2nd is 110, similarly 120,109,105 etc.

when you look deep into the figure, you can see the blue shade over there, which represents optimal boundary and with this boundary we can easily find the q value. Here during the 4th data point(109) the value touches the boundary hence it is optimal value of q(ACF).

Now let’s understand (PACF), again consider the same data, PACF assumes that if 100 is dependent on 110, it will also be partially dependent on all other values like 120,109,105.

with the help of this p,q,d we can predict future prediction.

2. ARMA : It is similar to ARIMA but we will not have differencing term as our data don’t follow any trend.

--

--

Rekha V S

Machine Learning and Deep Learning Enthusiast, Data Science Grad.