문제

I'm kind of new to Python and I want to find the root of an linear fit function inclusive errors.

I fitted the function with

import numpy as np
import scipy.optimize as op

def lin_fit(x, a, b):
    return a * x + b

...

popt, pconv = op.curve_fit(lin_fit, U, sqrt_I)
x = np.linspace(np.min(U), np.max(U), 100)
y = lin_fit(x, *popt)

Then I found the root with

def root(x):
    return lin_fit(x, *popt)

return op.fsolve(root, 0)

That was no problem, but I don't now, how to find the error of these roots.

Can anyone help?

도움이 되었습니까?

해결책

The error is contained in pconv, where the diagonal contains the variance for each one estimated coefficients, which in this case are a and b.

From the MathWorld the correlation coefficient r which measures the overall quality of the fit can be computed as:

sxy = pconv[0,1]*x.shape[0]
sxx = pconv[0,0]
syy = pconv[1,1]
r = (sxy**2/(sxx*syy))**0.5
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top