Pandas Autocorrelation Plot
Pandas offers an autocorrelation plot utility to visualize the linear relationship between lagged values for time series analysis.
from statsmodels.tsa.arima_process import ArmaProcess
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
ar2_process = ArmaProcess(ar=ar, ma=ma).generate_sample(nsample=136)
dates = pd.date_range('2012-03-15', '2012-09-20', freq='B')
df = pd.DataFrame({ 'ar_process': ar2_process}, index=dates)
df.head()
| ar_process | |
|---|---|
| 2012-03-15 | 0.786078 |
| 2012-03-16 | 1.093503 |
| 2012-03-19 | 1.135454 |
| 2012-03-20 | 0.799283 |
| 2012-03-21 | 0.218243 |
pd.plotting.autocorrelation_plot(df)
plt.title('Autocorrelation: pandas autocorrelation_plot')
plt.xlabel('Lags', fontsize=8)
plt.ylabel('Autocorrelation', fontsize=8)
plt.tight_layout()
plt.show()