我正在尝试使用Pandas和statsmodel在Python中运行Dickey-Fuller测试,它不断向我发出运行时警告。有谁知道是什么原因引起的?以下是代码和错误。提前谢谢。
代码:
import pandas as pd
import numpy as np
import matplotlib.pylab as plt
# %matplotlib inline
from matplotlib.pylab import rcParams
from statsmodels.tsa.stattools import adfuller
def test_stationarity(timeseries):
#Determing rolling statistics
rolmean = pd.Series.rolling(timeseries, window=12).mean()
rolstd = pd.Series.rolling(timeseries, window=12).std()
#Plot rolling statistics:
orig = plt.plot(timeseries, color='blue',label='Original')
mean = plt.plot(rolmean, color='red', label='Rolling Mean')
std = plt.plot(rolstd, color='black', label = 'Rolling Std')
plt.legend(loc='best')
plt.title('Rolling Mean & Standard Deviation')
plt.show(block=False)
#Perform Dickey-Fuller test:
print 'Results of Dickey-Fuller Test:'
dftest = adfuller(timeseries, autolag='AIC')
dfoutput = pd.Series(dftest[0:4], index=['Test Statistic','p-value','#Lags Used','Number of Observations Used'])
for key,value in dftest[4].items():
dfoutput['Critical Value (%s)'%key] = value
print dfoutput
rcParams['figure.figsize'] = 15, 6
# read and show the first 5 data sets in the terminal
data = pd.read_csv('daus.csv', index_col=0, parse_dates = True)
ts = data['#And_0DAUs']
# print data.head()
# # displays the data type of the data sets
# print '\n Data Types:'
# print data.dtypes
plt.plot(test_stationarity(ts))
plt.show()
输出:
/Library/Python/2.7/site-packages/statsmodels/compat/pandas.py:56: FutureWarning: The pandas.core.datetools module is deprecated and will be removed in a future version. Please use the pandas.tseries module instead.
from pandas.core import datetools
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/transforms.py:648: RuntimeWarning: invalid value encountered in absolute
inside = ((abs(dx0 + dx1) + abs(dy0 + dy1)) == 0)
Results of Dickey-Fuller Test:
Test Statistic NaN
p-value NaN
#Lags Used 0.000000
Number of Observations Used 22.000000
Critical Value (5%) -3.005426
Critical Value (1%) -3.769733
Critical Value (10%) -2.642501
dtype: float64