[Numpy-discussion] Change in default behavior of np.polyfit (original) (raw)

Andreas Nußbaumer nussbaum at uni-mainz.de
Fri Jun 1 08:24:48 EDT 2018


Hi,

in [1] the scaling factor for the covariance matrix of np.polyfit was discussed. The conclusion was, that it is non-standard and a patch might be in order to correct this. Pull request [2] changes the factor from chisq(popt)/(M-N-2) to chisq(popt)/(M-N) (with M=number of point, N=number of parameters) essentially removing the "-2". Clearly, this changes the result for the covariance matrix (but not the result for the polynomial coefficients) and therefore the current behavior if cov=True is set.

It should be noted, that scipy.optimize.curve_fit also uses the chisq(popt)/(M-N) as scaling factor (without "-2"). Therefore, the change would remove a discrepancy.

Additionally, patch [2] adds an option that sets the scaling factor of the covariance matrix to 1 . This can be useful in occasions, where the weights are given by 1/sigma with sigma being the (known) standard errors of (Gaussian distributed) data points, in which case the un-scaled matrix is already a correct estimate for the covariance matrix.

Best, Andreas

[1] http://numpy-discussion.10968.n7.nabble.com/Inconsistent-results-for-the-covariance-matrix-between-scipy-optimize-curve-fit-and-numpy-polyfit-td45582.html [2] https://github.com/numpy/numpy/pull/11197 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20180601/b1d098d6/attachment.html>



More information about the NumPy-Discussion mailing list