如何正确使用此函数的返回值? (蟒蛇)

时间:2020-01-09 02:52:58

标签: python pandas machine-learning

我正在我发现的与ML相关的类中实现函数。因此,我可以调用该函数,但是,我还要使用p值(也就是该函数在理论上返回的值:dfResults [1])。问题在于,当我调用该函数时,它只返回返回之前的print语句,而不返回实际值(应该为0.97 ish)。

下面是我的代码。解决该问题的任何建议将不胜感激。

class StationarityTests:
    def _init_(self):
        self.pValue = None
        self.isStationary = None

    def ADF_Stationarity_Test(self, timeseries, significance=.05, printResults = True):
            #Dickey-Fuller test:
            adfTest = adfuller(timeseries, autolag='AIC')
            self.SignificanceLevel = significance
            self.pValue = adfTest[1]

            if (self.pValue<self.SignificanceLevel):
                self.isStationary = True
            else:
                self.isStationary = False

            if printResults:
                dfResults = pd.Series(adfTest[0:4], index=['ADF Test Statistic','P-Value','# Lags Used','# Observations Used'])
                #Add Critical Values
                for key,value in adfTest[4].items():
                    dfResults['Critical Value (%s)'%key] = value
                print('Augmented Dickey-Fuller Test Results:')
                print(dfResults)
                return dfResults[1]

实施:

sTest = StationarityTests()
sTest.ADF_Stationarity_Test(mtum_df['Adj Close'], printResults = True)
print("Is the time series stationary? {0}".format(sTest.isStationary))

输出:我希望获得打印结果,但主要还是希望能够使用p值(0.97ish)进行进一步的计算

Augmented Dickey-Fuller Test Results:
ADF Test Statistic         0.215912
P-Value                    0.973140
# Lags Used                8.000000
# Observations Used     1682.000000
Critical Value (1%)       -3.434244
Critical Value (5%)       -2.863260
Critical Value (10%)      -2.567686
dtype: float64
Is the time series stationary? False

0 个答案:

没有答案
相关问题