2017-09-23 103 views
0

我正在做一個多元線性迴歸,並試圖選擇一些自變量的最佳子集。我想嘗試在「for」循環中執行所有1024個可能的組合,並根據條件編號和r平方保存最佳結果。我知道這兩種計算,給出類似的結果:如何從statsmodels.api.OLS獲取條件編號?

model = sm.OLS(salarray, narraycareer) 
results = model.fit() 
print results.summary() 

          OLS Regression Results        
============================================================================== 
Dep. Variable:      y R-squared:      0.425 
Model:       OLS Adj. R-squared:     0.409 
Method:     Least Squares F-statistic:      26.89 
Date:    Sat, 23 Sep 2017 Prob (F-statistic):   1.69e-27 
Time:      00:58:14 Log-Likelihood:    -1907.4 
No. Observations:     263 AIC:        3831. 
Df Residuals:      255 BIC:        3859. 
Df Model:       7           
Covariance Type:   nonrobust           
============================================================================== 
       coef std err   t  P>|t|  [95.0% Conf. Int.] 
------------------------------------------------------------------------------ 
const  535.9259  21.387  25.058  0.000  493.808 578.044 
x1   -675.5296 302.245  -2.235  0.026  -1270.744 -80.315 
x2   182.7168 436.493  0.419  0.676  -676.874 1042.307 
x3   -48.2603 126.141  -0.383  0.702  -296.671 200.151 
x4   445.0863 218.373  2.038  0.043  15.043 875.130 
x5   344.0092 219.896  1.564  0.119  -89.035 777.053 
x6   -41.5168  71.925  -0.577  0.564  -183.159 100.126 
x7   96.5430  30.595  3.156  0.002  36.293 156.793 
============================================================================== 
Omnibus:      96.442 Durbin-Watson:     1.973 
Prob(Omnibus):     0.000 Jarque-Bera (JB):    440.598 
Skew:       1.438 Prob(JB):      2.11e-96 
Kurtosis:      8.651 Cond. No.       61.7 
============================================================================== 

Warnings: 
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified. 
>>> 

但我不能找到如何走出條件數或R平方的任何文件。

謝謝!

回答

0

我發現它,或者Spyder ide在翻譯窗口中找到它。

>>> results.rsquared 
0.42465891683421031 
>>> results.condition_number 
61.715714331759621 
>>> > 

當我輸入「結果」。它給了一堆建議。 vim不能做的事情!