python求不确定度_用python求线性回归中的不确定性值

import statsmodels.api as sm

import numpy as np

y=[];x=[]

for item in arr:

x.append(item[0])

y.append(item[1])

# include constant in ols models, which is not done by default

x = sm.add_constant(x)

model = sm.OLS(y,x)

results = model.fit()

然后,您可以访问所需的值,如下所示。截距和斜率由下式给出:

^{pr2}$

我想你指的是标准误差,当你提到不确定度时,它们可以这样得到:results.bse # standard errors of the parameter estimates

# array([ 1.03372221e-03, 2.38463106e-05])

可以通过运行>>> print results.summary()

OLS Regression Results

==============================================================================

Dep. Variable: y R-squared: 0.997

Model: OLS Adj. R-squared: 0.996

Method: Least Squares F-statistic: 8029.

Date: Fri, 26 Sep 2014 Prob (F-statistic): 5.61e-36

Time: 05:47:08 Log-Likelihood: 162.43

No. Observations: 30 AIC: -320.9

Df Residuals: 28 BIC: -318.0

Df Model: 1

Covariance Type: nonrobust

==============================================================================

coef std err t P>|t| [95.0% Conf. Int.]

const -0.0369 0.001 -35.719 0.000 -0.039 -0.035

x1 0.0021 2.38e-05 89.607 0.000 0.002 0.002

==============================================================================

Omnibus: 7.378 Durbin-Watson: 0.569

Prob(Omnibus): 0.025 Jarque-Bera (JB): 2.079

Skew: 0.048 Prob(JB): 0.354

Kurtosis: 1.714 Cond. No. 220.

==============================================================================

Warnings:

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

This也可能对结果模型的属性摘要感兴趣。在

我没有与Excel中的LINEST进行比较。我也不知道这是否可能只使用googlechartsapi。在

你可能感兴趣的:(python求不确定度)