時間序列資料中的偏自相關
和自相關類似,偏自相關函式(PACF)測量時間序列與其自身不同延遲版本之間的相關係數。不過,它更進一步,會把較早時間點的影響去除。例如,order 3 的偏自相關函式,會在移除延遲 1 和 2 的影響後,回傳我們的時間序列(t_1、t_2、t_3、…)與延遲 3 個時間點的自身數值(t_4、t_5、t_6、…)之間的相關。
可以使用 statsmodels 函式庫中的 plot_pacf() 來衡量並繪製時間序列的偏自相關。
本練習屬於課程
使用 Python 視覺化時間序列資料
練習說明
- 從
statsmodels.graphics匯入tsaplots。 - 使用
tsaplots的plot_pacf()來繪製co2_levels中'co2'欄位的偏自相關。 - 將最大延遲設為 24。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import required libraries
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
____
# Display the partial autocorrelation plot of your time series
fig = ____(co2_levels[____], lags=____)
# Show plot
plt.show()