Gab*_*iel 18 python io statsmodels
(抱歉要问,但http://statsmodels.sourceforge.net/目前已关闭,我无法访问文档)
我正在使用线性回归statsmodels,基本上:
import statsmodels.api as sm
model = sm.OLS(y,x)
results = model.fit()
Run Code Online (Sandbox Code Playgroud)
我知道我可以打印出完整的结果集:
print results.summary()
Run Code Online (Sandbox Code Playgroud)
输出如下:
OLS Regression Results
==============================================================================
Dep. Variable: y R-squared: 0.952
Model: OLS Adj. R-squared: 0.951
Method: Least Squares F-statistic: 972.9
Date: Mon, 20 Jul 2015 Prob (F-statistic): 5.55e-34
Time: 15:35:22 Log-Likelihood: -78.843
No. Observations: 50 AIC: 159.7
Df Residuals: 49 BIC: 161.6
Df Model: 1
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [95.0% Conf. Int.]
------------------------------------------------------------------------------
x1 1.0250 0.033 31.191 0.000 0.959 1.091
==============================================================================
Omnibus: 16.396 Durbin-Watson: 2.166
Prob(Omnibus): 0.000 Jarque-Bera (JB): 3.480
Skew: -0.082 Prob(JB): 0.175
Kurtosis: 1.718 Cond. No. 1.00
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
Run Code Online (Sandbox Code Playgroud)
我需要一种方法只打印coef和 的值std err.
我可以访问coef:
print results.params
Run Code Online (Sandbox Code Playgroud)
但我发现无法打印出来std err.
我怎样才能做到这一点?
Gab*_*iel 30
应用这里给出的答案,我使用dir()打印results对象的所有属性.
之后我搜索了包含该std err值的那个,结果是:
print results.bse
Run Code Online (Sandbox Code Playgroud)
(不确定它b代表什么bse,但我猜se"标准错误"代表)
results.bse提供系数的标准误差,与 中列出的相同results.summary()。
使用 获得回归的标准误差results.scale**.5。
也与 相同np.sqrt(np.sum(results.resid**2)/results.df_resid),其中结果是您的拟合模型。