Thursday, October 17, 2019

Parameter Uncertainty in Numpy Polyfit

Say you want to fit a line to (x,y) data. With polyfit, you can say,

coeff = np.polyfit(x, y, 1)

With numpy 1.7 and greater, you can also request the estimated covariance matrix,

coeff, cov = np.polyfit(x, y, 1, cov=True)

The standard error on the parameters is the square-root of the diagonal elements

print(np.sqrt(np.diag(cov)))

This report referenced in the SO page is quite useful!

No comments: