result =adfuller(df['Passengers'])print('ADF Statistic: {}'.format(result[0]))print('p-value: {}'.format(result[1]))print('Critical Values:')for key, value in result[4].items():print('\t{}: {}'.format(key, value))
获取因变量的对数是降低滚动平均值增加速率的简单方法。
df_log = np.log(df) plt.plot(df_log)
让我们创建一个函数来运行两个测试,以确定给定的时间序列是否平稳。
defget_stationarity(timeseries): rolling_mean = timeseries.rolling(window=12).mean() rolling_std = timeseries.rolling(window=12).std() original = plt.plot(timeseries, color='blue', label='Original') mean = plt.plot(rolling_mean, color='red', label='Rolling Mean') std = plt.plot(rolling_std, color='black', label='Rolling Std') plt.legend(loc='best') plt.title('Rolling Mean & Standard Deviation') plt.show(block=False) result =adfuller(timeseries['Passengers'])print('ADF Statistic: {}'.format(result[0]))print('p-value: {}'.format(result[1]))print('Critical Values:')for key, value in result[4].items():print('\t{}: {}'.format(key, value))