

{"id":175543,"date":"2021-03-10T10:49:03","date_gmt":"2021-03-10T05:19:03","guid":{"rendered":"https:\/\/www.jigsawacademy.com\/?p=175543"},"modified":"2022-07-06T19:22:38","modified_gmt":"2022-07-06T13:52:38","slug":"blogs-ai-ml-autocorrelation","status":"publish","type":"post","link":"https:\/\/www.jigsawacademy.com\/blogs\/ai-ml\/autocorrelation\/","title":{"rendered":"Autocorrelation: A Comprehensive Guide In 2021"},"content":{"rendered":"\r\n<h2><strong>Introduction<\/strong><\/h2>\r\n\r\n\r\n\r\n<p>The processes of forecasting and analysis of time-series use plotting of partial autocorrelation and autocorrelation. The plots summarize graphically the strength of a relationship in a time-series where one can compare the present series with prior steps of the time series. However, the differences between the two types of correlation need further explanation especially for those who are new to the forecasting of time-series.<\/p>\r\n\r\n\r\n\r\n<p>In this article let us look at:<\/p>\r\n\r\n\r\n\r\n<ol>\r\n<li><strong><strong><a class=\"rank-math-link\" href=\"#Correlation-and-Autocorrelation\">Correlation and Autocorrelation<\/a><\/strong><\/strong><\/li>\r\n<li><strong><a class=\"rank-math-link\" href=\"#Dataset-for-Minimum-Daily-Temperatures\">Dataset for Minimum Daily Temperatures<\/a><\/strong><\/li>\r\n<li><strong><a class=\"rank-math-link\" href=\"#Partial-Autocorrelation-Function\">Partial Autocorrelation Function<\/a><\/strong><\/li>\r\n<li><strong><a class=\"rank-math-link\" href=\"#Intuition-for-ACF-and-PACF-Plots\">Intuition for ACF and PACF Plots<\/a><\/strong><\/li>\r\n<\/ol>\r\n\r\n\r\n\r\n<h2 id=\"Correlation-and-Autocorrelation\" class=\"has-vivid-cyan-blue-color has-text-color\">1. <strong>Correlation and Autocorrelation<\/strong><\/h2>\r\n\r\n\r\n\r\n<p>In statistical correlation, the relationship strength between 2-variables is studied using bell curve Gaussian distribution for each variable&#8217;s distribution of autocorrelation in regression. Then the correlation between variables is described by the autocorrelation formula\u2019s Pearson Coefficient to describe the inter-variables correlation. Its value lies between values 1 and -1 showing positive, negative and zero correlation when the coefficient is zero. Thus when one uses this with previous time steps the lags can calculate the correlation of the same time series known as the ACF or Auto Correlation Function or Serial Correlation. The plot is called the autocorrelation plot or correlogram.<\/p>\r\n\r\n\r\n\r\n<p>Now one can calculate the properties of autocorrelation function or correlation for time-series observations with the lag observations. Since the same series at previous times is used for time-series correlation observations this is called the autocorrelation function of a serial correlation.<\/p>\r\n\r\n\r\n\r\n<p>For an example, use the minimum daily temperatures dataset described below.\u00a0<\/p>\r\n\r\n\r\n\r\n<h2 id=\"Dataset-for-Minimum-Daily-Temperatures\" class=\"has-vivid-cyan-blue-color has-text-color\">2. <strong>Dataset for Minimum Daily Temperatures<\/strong><\/h2>\r\n\r\n\r\n\r\n<p>Take the Australian Bureau of Meteorology\u2019s daily minimum temperatures in Australia\u2019s Melbourne city for the decade 1981-90. The temperatures are Celsius and it has over 3,650 observations. Firstly, <a class=\"rank-math-link\" href=\"https:\/\/raw.githubusercontent.com\/jbrownlee\/Datasets\/master\/daily-min-temperatures.csv\" target=\"_blank\" rel=\"noopener\">download the dataset<\/a> into the current working directory and store it with the \u201c<em>daily-minimum-temperatures.csv<\/em>\u2018\u201d filename to graph the time-series and load the Minimum Daily Temperatures as described. Use import and read-CSV from pandas and the import pyplot from matplotlib setting header and index-col to zero. The resultant loaded dataset creates the time-series line-plot for the dataset as a Pandas Series as shown below.<\/p>\r\n\r\n\r\n\r\n<p>Plotting and calculating the autocorrelation plot for the Minimum Daily Temperatures using the statsmodels library and <a class=\"rank-math-link\" href=\"http:\/\/statsmodels.sourceforge.net\/devel\/generated\/statsmodels.graphics.tsaplots.plot_acf.html\" target=\"_blank\" rel=\"noopener\">plot_acf()<\/a> function using pandas to read-CSV, matplotlib to import pyplot and studying the resulting 2D plot with X-axis having the lag values and Y-axis showing the autocorrelation in time series, the correlation lies between values of 1 and -1. For such plots, the confidence or cone-like intervals are set to 95% by default meaning outside the code correlation values are not statistical flukes but rather are correlations themselves.<\/p>\r\n\r\n\r\n\r\n<p>Since all of the lag values in the ACF time series are considered the plot has autocorrelation problems and is noisy. To make it easier to read the lag number on X-axis is set to 50 lags and the new plot for properties is as below.<\/p>\r\n\r\n\r\n\r\n<h2 id=\"Partial-Autocorrelation-Function\" class=\"has-vivid-cyan-blue-color has-text-color\">3. <strong>Partial Autocorrelation Function<\/strong><\/h2>\r\n\r\n\r\n\r\n<p>The process of Partial Autocorrelation is similar to an autocorrelation description of a time (in R) series observation with prior time observation steps with the removal of observations intervening. The partial autocorrelation function- PACF or partial autocorrelation with k lag will provide the correlation after removing any correlations of shorter lag terms. It has both direct and indirect types of correlations where the indirect ones provide the linear function of the observed values with the time-step intervening observations.<\/p>\r\n\r\n\r\n\r\n<p>In short, the indirect correlations removed by partial autocorrelation function form PACF intuition. Using the same dataset the plot for the PACF in the dataset for the first 50 lags using the statsmodels library <a href=\"http:\/\/statsmodels.sourceforge.net\/devel\/generated\/statsmodels.graphics.tsaplots.plot_pacf.html\" target=\"_blank\" rel=\"noopener\">plot_pacf()<\/a> is shown below.<\/p>\r\n\r\n\r\n\r\n<h2 id=\"Intuition-for-ACF-and-PACF-Plots\" class=\"has-vivid-cyan-blue-color has-text-color\"><strong>4. Intuition for ACF and PACF Plots<\/strong><\/h2>\r\n\r\n\r\n\r\n<p>The PACF and ACF plots of a time series provide consequences of autocorrelation and the intuition of the correlation.\u00a0<\/p>\r\n\r\n\r\n\r\n<p><strong>Autoregression Intuition<\/strong><\/p>\r\n\r\n\r\n\r\n<p>Using the time series plot of the AR- autoregression process having a lag of <em>k<\/em>, the ACF relationship\u2019s ACF provides indirect and direct dependence information on the correlation between the particular observation and observations of this time series at prior time steps. We see that the AR(k) time series is provided with a k lag since the relation\u2019s inertia will in subsequent values of lag weaken the effects causing it to trail off. This suggests that the PACF describes an only and direct relationship between lag and its observation meaning there is no correlation beyond the k lag value which tallies with the expectations of the AR(k) process and its PACF and ACF plots.<\/p>\r\n\r\n\r\n\r\n<p><strong>Intuition for PACF and ACF Plots<\/strong><\/p>\r\n\r\n\r\n\r\n<p>Use the MA- Moving Average process with a k lag on a time-series. Note that this method uses the time-series of residual errors from prior predictions or that it uses errors made on recent forecasts to correct future forecasts in autocorrelation. The plots generated show the MA(k) ACF process has recent values strong correlation up to the lag of k, declining to no or low correlation thereafter in the process. The PACF plot is also expected to show a strong relationship until the lag preset and trails off beyond the value. Both plots generated in such a case prove the expectations!<\/p>\r\n\r\n\r\n\r\n<h2><strong>Conclusion<\/strong><\/h2>\r\n\r\n\r\n\r\n<p>From the discussion above, one can note that ACF and PACF regression models provide a time series correlation comparison with prior sets of the same meeting all expectations for the generation of autocorrelation results. Need to know more about the auto-correlation time series ACF and PACF? Try these resources. Wikipedia\u2019s <a href=\"https:\/\/en.wikipedia.org\/wiki\/Autocorrelation\" target=\"_blank\" rel=\"noopener\">Autocorrelation<\/a>, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Correlogram\" target=\"_blank\" rel=\"noopener\">Correlogram<\/a>, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Correlation_and_dependence\" target=\"_blank\" rel=\"noopener\">Correlation and dependence<\/a>, <a class=\"rank-math-link\" href=\"https:\/\/en.wikipedia.org\/wiki\/Partial_autocorrelation_function\" target=\"_blank\" rel=\"noopener\">Partial autocorrelation function<\/a> and <a href=\"https:\/\/amzn.to\/31OLnFH\" target=\"_blank\" rel=\"noopener\">\u00a0Forecasting and Control<\/a> Time Series Analysis.<\/p>\r\n\r\n\r\n\r\n<p>There are no right or wrong ways of learning AI and ML technologies \u2013 the more, the better! These valuable resources can be the starting point for your journey on how to learn Artificial Intelligence and Machine Learning. Do pursuing AI and ML interest you? If you want to step into the world of emerging tech, you can accelerate your career with this\u00a0<strong><a href=\"https:\/\/www.jigsawacademy.com\/full-stack-machine-learning-artificial-intelligence\/\">Machine Learning And AI Courses<\/a>\u00a0<\/strong>by Jigsaw Academy.<\/p>\r\n\r\n\r\n\r\n<h2>ALSO READ<\/h2>\r\n\r\n\r\n\r\n<ul>\r\n<li><strong><a class=\"rank-math-link\" href=\"https:\/\/www.jigsawacademy.com\/blogs\/ai-ml\/time-series-dataset\">8 Important Time Series Datasets For Machine Learning<\/a><\/strong><\/li>\r\n<li><strong><a class=\"rank-math-link\" href=\"https:\/\/www.jigsawacademy.com\/blogs\/ai-ml\/time-series-forecasting\/\">Time Series Forecasting \u2013 An Interesting Overview(2021)<\/a><\/strong><\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p>&nbsp;<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Introduction The processes of forecasting and analysis of time-series use plotting of partial autocorrelation and autocorrelation. The plots summarize graphically the strength of a relationship in a time-series where one can compare the present series with prior steps of the time series. However, the differences between the two types of correlation need further explanation especially [&hellip;]<\/p>\n","protected":false},"author":181,"featured_media":175547,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1126],"tags":[7453,1292,7456,7452,7451,7454,7458,7455,7457],"form":[1499],"acf":[],"_links":{"self":[{"href":"https:\/\/www.jigsawacademy.com\/wp-json\/wp\/v2\/posts\/175543"}],"collection":[{"href":"https:\/\/www.jigsawacademy.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jigsawacademy.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jigsawacademy.com\/wp-json\/wp\/v2\/users\/181"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jigsawacademy.com\/wp-json\/wp\/v2\/comments?post=175543"}],"version-history":[{"count":2,"href":"https:\/\/www.jigsawacademy.com\/wp-json\/wp\/v2\/posts\/175543\/revisions"}],"predecessor-version":[{"id":238588,"href":"https:\/\/www.jigsawacademy.com\/wp-json\/wp\/v2\/posts\/175543\/revisions\/238588"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jigsawacademy.com\/wp-json\/wp\/v2\/media\/175547"}],"wp:attachment":[{"href":"https:\/\/www.jigsawacademy.com\/wp-json\/wp\/v2\/media?parent=175543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jigsawacademy.com\/wp-json\/wp\/v2\/categories?post=175543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jigsawacademy.com\/wp-json\/wp\/v2\/tags?post=175543"},{"taxonomy":"form","embeddable":true,"href":"https:\/\/www.jigsawacademy.com\/wp-json\/wp\/v2\/form?post=175543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}