气温是带漂移的随机游走吗?
ARMA 模型用于气候变化预测较为简化,但它能很好地串联本课程涉及的许多主题。
DataFrame temp_NY 包含纽约中央公园 1870-2016 年的年度平均气温(数据从 NOAA 下载,链接见此处:here)。请绘制该数据,并检验它是否符合带漂移的随机游走。
本练习是课程的一部分
Python 中的时间序列分析
练习说明
- 使用
pd.to_datetime()将按年份的索引转换为 datetime 对象;由于数据是年度频率,请传入参数format='%Y'。 - 使用
.plot()绘制数据。 - 使用
adfuller函数计算增广 Dickey-Fuller(ADF)检验的 p 值。 - 将 ADF 检验结果保存到
result,并打印result[1]中的 p 值。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import the adfuller function from the statsmodels module
from statsmodels.tsa.stattools import adfuller
# Convert the index to a datetime object
temp_NY.index = pd.to_datetime(___.___, format=___)
# Plot average temperatures
temp_NY.___
plt.show()
# Compute and print ADF p-value
result = ___(temp_NY['TAVG'])
print("The p-value for the ADF test is ", result[1])