เริ่มต้นด้วยการดู Autocorrelation
เนื่องจากอนุกรมอุณหภูมิ temp_NY เป็น random walk แบบมี drift ให้หาผลต่างอันดับแรกเพื่อทำให้อนุกรมเป็น stationary จากนั้นคำนวณ ACF และ PACF ของตัวอย่าง ซึ่งจะช่วยให้เห็นแนวทางในการกำหนด order ของโมเดล
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การวิเคราะห์อนุกรมเวลาด้วย Python
คำแนะนำการฝึกหัด
- นำเข้าโมดูลสำหรับพล็อต ACF และ PACF ของตัวอย่าง
- หาผลต่างอันดับแรกของ DataFrame
temp_NYโดยใช้เมธอด.diff()ของ pandas - สร้าง subplot สองอัน สำหรับพล็อต 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()