몸 풀기: 자기상관 살펴보기
기온 시계열 temp_NY는 추세가 있는 랜덤 워크이므로, 1차 차분을 해서 정상성을 갖도록 만들어요. 그런 다음 표본 ACF와 PACF를 계산하세요. 이렇게 하면 모형 차수에 대한 단서를 얻을 수 있어요.
이 연습은 강의의 일부입니다
Python으로 배우는 시계열 분석
연습 안내
- 표본 ACF와 PACF를 그리기 위한 모듈을 임포트하세요.
- pandas의
.diff()메서드를 사용해 DataFrametemp_NY의 1차 차분을 구하세요. - 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()