# Computing Autocorrelations of a Numeric Series

Autocorrelation is a fundamental concept in time series analysis. It measures the correlation between a time series and a lagged version of itself, which can provide insights into patterns and trends over time. In other words, it measures how similar a data point is to the previous data point(s) in the series. It is useful in analyzing time-series data because it can reveal patterns in the data that might not be apparent from a simple visual inspection. In this thread, different methods will be discussed on how to compute autocorrelations of a numeric time series. If you want to learn how to compute other metrics, you can check out the threads of:

#### 1. Using "autocorr()" method:

• The `autocorr()` method of Pandas is used to compute the autocorrelation of a numeric time series. It calculates the correlation between a time series and a lagged version of itself.
• It takes an integer argument `lag`, which specifies the number of lags to use in the autocorrelation calculation. The default value is 1, which computes the autocorrelation at lag 1.

#### 2. Using "rolling()" and "corr()":

• The `rolling()` method creates a rolling or sliding window of the time series with a specified size (`window=2`) and applies a function to the data within that window. The argument `window=2` means that each window consists of two consecutive values from the time series.
• The sliding window approach divides the time series into overlapping subsets, or windows, of a fixed length and computes the autocorrelation between these windows.
• The `corr()` method is used to calculate the correlation between two series and here, it computes the correlation between the rolling window and a lagged version of the time series.
• The `shift()` method is responsible for shifting the index of a time series forward or backward by a specified number of periods called lag. (Default value is 1)

#### 3. Using "shift()" method:

• The `shift()` method is used for shifting the index of a time series forward or backward by a specified number of periods called lag.
• In this example, the `corr()` method is used to find the autocorrelation between the original series and the shifted series created with the help of the `shift()` method.

#### 4. Using "np.corrcoef()" method:

• The `corrcoef()` function computes the Pearson correlation coefficient between two arrays or as in this example, between two series.
• We computed the correlation between the original time series and a lagged version of itself where the lag is determined by slicing the series using `seriess[:-lag]` and `series[lag:]` using a `lag` of value `1`.