2017-02-16 62 views
1

我的代碼熊貓OLS線正在正常工作,但我無法拉PARAMS在另一個相關的功能,使用方法:熊貓OLS - 拉不工作PARAMS

ES_15M_LR = pd.ols(y = ES_15M_Last_300_Periods['Close'], x = ES_15M_Last_300_Periods['Date']) 

上面的代碼的偉大工程,但當我嘗試從這個拉PARAMS我得到的錯誤:

AttributeError: 'OLS' object has no attribute 'params' 

舉例來說,我想:

ES_15M_LR.params 

除了作爲:

ES_15M_LR.params.x 

...拉x係數(斜率)。如上所述得到相同的錯誤。不過,我可以看到,如預期的統計信息工作:

enter image description here

我似乎就是不能夠自動拉參數,我需要爲其他功能的變量。任何人都可以協助

回答

1

我從來沒有使用OLS熊貓,但它似乎曾用於存在熊貓和移動到statsmodel包。看來文檔也過時或不正確,但ES_15M_LR.beta應該做的伎倆。

3

首先,強烈建議您使用statsmodels因爲...

pandas.stats.ols , pandas.stats.plm and pandas.stats.var routines are deprecated and will be removed in a future version (GH6077 : MIGRATE: move stats code to statsmodels/deprecate in pandas #6077)

和關於param訪問,

import numpy as np 
import pandas as pd 
import statsmodels.api as sm 

df = pd.DataFrame(np.random.randint(0,100,size=(100, 2)), columns=list('AB')) 

model = sm.OLS(df['A'], df['B']) 
fit = model.fit() 

print fit.params 

B 0.724865 

print fit.summary() 

          OLS Regression Results        
============================================================================== 
Dep. Variable:      A R-squared:      0.533 
Model:       OLS Adj. R-squared:     0.528 
Method:     Least Squares F-statistic:      113.0 
Date:    Thu, 16 Feb 2017 Prob (F-statistic):   4.66e-18 
Time:      10:27:13 Log-Likelihood:    -509.62 
No. Observations:     100 AIC:        1021. 
Df Residuals:      99 BIC:        1024. 
Df Model:       1           
Covariance Type:   nonrobust           
============================================================================== 
       coef std err   t  P>|t|  [0.025  0.975] 
------------------------------------------------------------------------------ 
B    0.7249  0.068  10.629  0.000  0.590  0.860 
============================================================================== 
Omnibus:      3.447 Durbin-Watson:     1.724 
Prob(Omnibus):     0.178 Jarque-Bera (JB):    2.856 
Skew:       0.301 Prob(JB):      0.240 
Kurtosis:      2.432 Cond. No.       1.00 
============================================================================== 

並檢查sm.add_constant()也。