我正在进行多元线性回归,并尝试选择多个自变量的最佳子集。我想尝试在“for”循环中完成所有1024种可能的组合,并根据条件数和r平方保存最佳结果。我知道它会计算两者,给出如下结果:
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 :(得分:2)
我找到了它,或者Spyder ide在翻译窗口找到了它。
>>> results.rsquared
0.42465891683421031
>>> results.condition_number
61.715714331759621
>>> >
当我输入“结果”时。它提出了一堆建议。什么东西vim不做!