scipy.odr输出拦截和斜率

时间:2016-09-14 14:05:32

标签: python scipy regression

我正在尝试绘制广告odr回归。我使用这篇文章中的代码作为例子: sample code 这是我的代码:

# regressione ODR  
import scipy.odr as odr
def funzione(B,x):
    return B[0]*x+B[1]
linear= odr.Model(funzione)
variabili=odr.Data(database.valore_rut,database.valore_cap)
regressione_ortogonale=odr.ODR(variabili,linear,beta0=[1., 2.])
output=regressione_ortogonale.run()    
output.pprint()

这是输出

Beta: [ 1.00088365  1.78267543]
Beta Std Error: [ 0.04851125  0.41899546]
Beta Covariance: [[ 0.00043625 -0.00154797]
[-0.00154797  0.03254372]]
Residual Variance: 5.39450361153
Inverse Condition #: 0.109803542662
Reason(s) for Halting:
Sum of squares convergence

在哪里可以找到截距和斜线来画线?

由于

1 个答案:

答案 0 :(得分:0)

属性output.beta包含您在代码中调用B的系数。因此,斜率为output.beta[0],截距为output.beta[1]

要绘制一条线,您可以执行以下操作:

# xx holds the x limits of the line to draw.  The graph is a straight line,
# so we only need the endpoints to draw it.
xx = np.array([start, stop])  
yy = funzione(output.beta, xx)
plot(xx, yy)