これはthe docsの例の果肉アウトバージョンです:
import numpy as np
import scipy.odr.odrpack as odrpack
np.random.seed(1)
N = 100
x = np.linspace(0,10,N)
y = 3*x - 1 + np.random.random(N)
sx = np.random.random(N)
sy = np.random.random(N)
def f(B, x):
return B[0]*x + B[1]
linear = odrpack.Model(f)
# mydata = odrpack.Data(x, y, wd=1./np.power(sx,2), we=1./np.power(sy,2))
mydata = odrpack.RealData(x, y, sx=sx, sy=sy)
myodr = odrpack.ODR(mydata, linear, beta0=[1., 2.])
myoutput = myodr.run()
myoutput.pprint()
# Beta: [ 3.02012862 -0.63168734]
# Beta Std Error: [ 0.01188347 0.05616458]
# Beta Covariance: [[ 0.00067276 -0.00267082]
# [-0.00267082 0.01502792]]
# Residual Variance: 0.209906660703
# Inverse Condition #: 0.105981202542
# Reason(s) for Halting:
# Sum of squares convergence