開始使用免費開始

時間序列資料中的自我相關(Autocorrelation)

在時間序列分析中,自我相關(autocorrelation)是指時間序列與其自身滯後版本之間的相關性。例如,order 3 的自我相關會回傳時間序列與其自身滯後 3 個時間點之間的相關係數。

常見的做法是使用自我相關函數(ACF)圖,也稱為自我關聯圖,來視覺化時間序列的自我相關。statsmodels 函式庫中的 plot_acf() 函式可用來計算並繪製時間序列的自我相關。

本練習屬於課程

使用 Python 視覺化時間序列資料

檢視課程

練習說明

  • statsmodels.graphics 匯入 tsaplots
  • 使用 tsaplotsplot_acf() 來繪製 co2_levels'co2' 欄位的自我相關。
  • 將最大滯後指定為 24。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import required libraries
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
from ____ import ____

# Display the autocorrelation plot of your time series
fig = ____(co2_levels[____], lags=____)

# Show plot
plt.show()
編輯並執行程式碼