# Guide To AC and PAC Plots In Time Series

when we talk about the time-series data, many factors affect the time series, but the only thing that affects the lagged version of the variable is the time series data itself

## Time series

In time-series, data points are gathered in time order. Therefore, changes occurring in any variable with the time can cause the generation of time series. Furthermore, because changes are gathered with an adjacent time interval, there can be a relationship between the changes. This relationship can be considered as a correlation.

## Correlation

In statistical analysis, correlation is a mathematical representation of the relation between two variables, telling us how a variable affects another variable. For example, when we talk about the time-series data, many factors affect the time series, but the only thing that affects the lagged version of the variable is the time series data itself. For example, the ups and down of any share depend on its last day’s magnitude in the share market. Correlation in mathematics varies between -1 to 1 and +1 denotes the strong positive relationship, and -1 denotes the strong negative relationship.

## Autocorrelation

We use autocorrelation to represent the degree of similarity between changes in two successive time intervals in a time series. Conceptually it is similar to correlation; the only difference in the measurement is that in correlation, we find the degree of relationship between two variables, but in autocorrelation, we find the degree of relation between two versions of time series, which means the relation of a time series to its own lagged time series or older time series.

#### AIM Daily XO

##### Join our editors every weekday evening as they steer you through the most significant news of the day, introduce you to fresh perspectives, and provide unexpected moments of joy

There can be many applications to use autocorrelation as a tool, like using autocorrelation. We can predict the stock situation for tomorrow or tell the prediction about the upcoming rain season.

Autocorrelation can measure the relationship between the present and its past values in a time series, and it also varies between 1 to -1, similar to the correlation. Autocorrelation becomes easier when we use a graph to measure it. Next, in the topic, we are going to discuss the autocorrelation graph. And make a graph using python and its library.

We can make an autocorrelation plot using matplotlib and statsmodel libraries. Let’s see how we can do that in google colab.

Importing the libraries.

Input:

``````import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf``````

We will discuss the autocorrelation in two kinds of data sets, one is increasing time series, and the other one is decreasing time series.

In increasing time series, we have Google share price data. In which we are provided with the price of Google shares for the year 2005. We will see in the data how it is increasing and how the time series is autocorrelated.

Input:

``````data = pd.read_csv("/content/drive/MyDrive/Yugesh/AC and PAC plots/google.txt",encoding="utf16",sep = "\t",index_col = 'date')
data``````

Output:

Here we can see how we can draw a plot to know about its increasing nature.

Input:

``data.plot()``

Output:

Here we can see that the value of shares decreased for some time, and then the growth of prize is increasing with time.

Let’s make an autocorrelation plot to know about the degree of the relation between time series and its own lagged part.

Here we are using matplotlib to make the autocorrelation plot.

Input:

``````plt.acorr(data['price'], maxlags = 10)
print("The Autocorreleation plot for the data is:")
plt.grid(True)
plt.show()``````

Output:

Here we can see that the degree of autocorrelation in time series is mostly on the positive side, and at some point, it has been of perfect positive correlated nature. So by this plot, we can infer that the present time series is highly correlated with the older time series.

The stats model gives a better-autocorrelated plot. In the statsmodel library, module tsapplots provides this facility. let’s try to make that also.

Input:

``plot_acf(data);``

Output:

Here in the plot, the blue area shows the confidence interval, and the candles represent the autocorrelation levels at different points of the time series. We can also see that the relationship between two points in the time series follows a consecutively positive nature.

Let’s plot this also for our alcohol dataset, which is decreasing with time.

Input:

``````data1 = pd_csv("/content/drive/MyDrive/Yugesh/Trend, Season, Cycle/AlcoholSale.csv",index_col = 'DATE')
data1``````

Output:

Let’s draw the line graph to understand the nature of time series.

Input:

``data1.plot()``

Output:

Here we can see the value of units of sale of alcohol is decreasing over time.

Let’s check for the autocorrelation of time series using the autocorrelation plot.

Input:

``plot_acf(data1);``

Output:

We can also see that the relationship between the points and the past time series has a strong positive nature.

Here we can say that the autocorrelation is not dependent on the behaviour or nature of time series if the time series is unidirectional. On the contrary, every point in the time series helps to define the nature of the whole time series.

Partial autocorrelation :

Mathematically Partial autocorrelation in a time series can be considered the degree of correlation between an observation in a given time with the observations own lagged value, unlike autocorrelation, where we find the relationship between a time series point to the whole past time series.

For example, in daily temperature prediction, we are predicting tomorrow’s temperature based on today’s temperature without considering any other older data points. Today’stemperature is the consecutive lagged data point, and tomorrow’s temperature prediction is the present value. The relationship between the temperature tomorrow and today without considering any older data is partial autocorrelation.

We can visualize the partial autocorrelation plot using the statsmodels library of python. Let’s see how we can do this with the data which we have imported before.

Visualising the partial autocorrelation plot for the google share price data.

Input:

``plot_pacf(data);``

Output:

Here we can see that the starting two points are highly correlated; after two points, we can see the correlation between the points. So there will always be a high co-relationship between the starting two points of the time series.

Let’s check the partial autocorrelation on alcohol data.

Input:

``plot_pacf(data1);``

Output:

Here we can compare the partial autocorrelation plot of both data. For google share price data, in the line graph, we saw that the deviation of the time series with time was high. According to those deviations, the deviation in partial autocorrelation is varying so much from the zeroth line. Still, in alcohol data, we have seen in the line graph that decreasing order of UNIT was stable with time, so all the candles in the partial autocorrelation plot are mostly lying around the zeroth line.

Here in the article, we have seen how we can make autocorrelation(AC) plots and partial autocorrelation (PAC) plots and make inferences for the time series.

References

Here in the article all the information is gathered from

## The Deep Learning Curve is a technology-based podcast hosted by Vijayalakshmi Anandan - Video Presenter and Podcaster at Analytics India Magazine. This podcast is the narrator's journey of curiosity and discovery in the world of technology.

Yugesh is a graduate in automobile engineering and worked as a data analyst intern. He completed several Data Science projects. He has a strong interest in Deep Learning and writing blogs on data science and machine learning.

## Our Upcoming Events

24th Mar, 2023 | Webinar

27-28th Apr, 2023 I Bangalore
Data Engineering Summit (DES) 2023

23 Jun, 2023 | Bangalore
MachineCon India 2023 [AI100 Awards]

21 Jul, 2023 | New York
MachineCon USA 2023 [AI100 Awards]

### Telegram group

Discover special offers, top stories, upcoming events, and more.

### Discord Server

Stay Connected with a larger ecosystem of data science and ML Professionals

### Deepfakes Are Elevating Meme Culture, But At What Cost?

A popular meme-maker spoke to Analytics India Magazine on the rise of generative AI, stating, “Eleven Labs has completely changed the game”.

### The Rising 2023: Incredible Stories of Women Leadership

The 5th edition of Rising spanned across two days and was a blend of personal narratives with informative sessions

### Why Responsible AI is Just Fluff Talk for Microsoft, Others

The move is a big red flag that exposes Big Tech’s hypocritical intentions around responsible AI.

### Data Science Hiring Process at Park+

Park+ is currently hiring data analysts in Gurugram

### Is solid-state LiDAR the key to autonomous driving?

Even if commercially accessible fully autonomous vehicles are still years away, lowering the cost of state-of-art LIDAR can spur development.

### Larry Page’s ‘AI Vision’ Dies with Google

Google owns 93% of the search engine market share whereas Microsoft has a mere 3%

### The Rising 2023: Best Firms for Women in Tech

AIM gave away awards in two prestigious categories: ‘Best Firms for Women in Tech Awards’ & ‘Women in Tech Leadership Award’ at The Rising 2023

### Council Post: The Rise of Generative AI and Living Content

In this era of content, the use of technology, such as AI and data analytics, is becoming increasingly important as it can help content creators personalise their content, improve its quality, and reach their target audience with greater efficacy. AI writing has arrived and is here to stay. Once we overcome the initial need to cling to our conventional methods, we can begin to be more receptive to the tremendous opportunities that these technologies present.

### Meet the MVP of GPT-4 Team

The core contributor of GPT4 has mostly kept a low profile

### OpenAI Publishes Yet Another Lame Paper

Published in collaboration with OpenResearch and the University of Pennsylvania, the paper tries to qualify GPT technology as a general-purpose technology