我试图在python的statsmodels中运行Dickey-Fuller测试,但出现错误 [英] I am trying to run Dickey-Fuller test in statsmodels in Python but getting error

查看:400
本文介绍了我试图在python的statsmodels中运行Dickey-Fuller测试,但出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在python的statsmodels中运行Dickey-Fuller测试,但出现错误P 从python 2.7&运行熊猫0.19.2版.数据集来自Github,并导入了相同的数据

I am trying to run Dickey-Fuller test in statsmodels in Python but getting error P Running from python 2.7 & Pandas version 0.19.2. Dataset is from Github and imported the same

enter code here

 from statsmodels.tsa.stattools import adfuller
    def test_stationarity(timeseries):

    print 'Results of Dickey-Fuller Test:'
        dftest = ts.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


    test_stationarity(tr)

给我以下错误:

Results of Dickey-Fuller Test:
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-15-10ab4b87e558> in <module>()
----> 1 test_stationarity(tr)

<ipython-input-14-d779e1ed35b3> in test_stationarity(timeseries)
     19     #Perform Dickey-Fuller test:
     20     print 'Results of Dickey-Fuller Test:'
---> 21     dftest = ts.adfuller(timeseries, autolag='AIC' )
     22     #dftest = adfuller(timeseries, autolag='AIC')
     23     dfoutput = pd.Series(dftest[0:4], index=['Test Statistic','p-value','#Lags Used','Number of Observations Used'])

C:\Users\SONY\Anaconda2\lib\site-packages\statsmodels\tsa\stattools.pyc in adfuller(x, maxlag, regression, autolag, store, regresults)
    209 
    210     xdiff = np.diff(x)
--> 211     xdall = lagmat(xdiff[:, None], maxlag, trim='both', original='in')
    212     nobs = xdall.shape[0]  # pylint: disable=E1103
    213 

C:\Users\SONY\Anaconda2\lib\site-packages\statsmodels\tsa\tsatools.pyc in lagmat(x, maxlag, trim, original)
    322     if x.ndim == 1:
    323         x = x[:,None]
--> 324     nobs, nvar = x.shape
    325     if original in ['ex','sep']:
    326         dropidx = nvar

ValueError: too many values to unpack

推荐答案

tr 必须类似于一维数组,如您所见

tr must be a 1d array-like, as you can see here. I don't know what is tr in your case. Assuming that you defined tr as the dataframe that contains the time serie's data, you should do something like this:

tr = tr.iloc[:,0].values

然后 adfuller 将能够读取数据.

这篇关于我试图在python的statsmodels中运行Dickey-Fuller测试,但出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆