開始使用免費開始

先「暖」身:查看自我相關

由於溫度時間序列 temp_NY 是帶趨勢的隨機漫步,請取一次差分讓它成為定態序列。接著計算樣本 ACF 與 PACF。這會幫助你判斷模型的階數。

本練習屬於課程

Python 中的時間序列分析

檢視課程

練習說明

  • 匯入用來繪製樣本 ACF 與 PACF 的模組
  • 使用 pandas 的 .diff() 方法,對資料框 temp_NY 取一次差分
  • 建立兩個子圖以繪製 ACF 與 PACF
    • 繪製差分後序列的樣本 ACF
    • 繪製差分後序列的樣本 PACF

動手互動練習

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

# Import the modules for plotting the sample ACF and PACF
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf

# Take first difference of the temperature Series
chg_temp = ___.___
chg_temp = chg_temp.dropna()

# Plot the ACF and PACF on the same page
fig, axes = plt.subplots(2,1)

# Plot the ACF
plot_acf(___, lags=20, ax=axes[0])

# Plot the PACF
plot_pacf(___, lags=20, ax=axes[1])
plt.show()
編輯並執行程式碼