numpy.polyfit有什么错误? [英] What's the error of numpy.polyfit?
本文介绍了numpy.polyfit有什么错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用numpy.polyfit
进行物理计算,因此我需要误差的大小.
I want to use numpy.polyfit
for physical calculations, therefore I need the magnitude of the error.
推荐答案
If you specify full=True
in your call to polyfit
, it will include extra information:
>>> x = np.arange(100)
>>> y = x**2 + 3*x + 5 + np.random.rand(100)
>>> np.polyfit(x, y, 2)
array([ 0.99995888, 3.00221219, 5.56776641])
>>> np.polyfit(x, y, 2, full=True)
(array([ 0.99995888, 3.00221219, 5.56776641]), # coefficients
array([ 7.19260721]), # residuals
3, # rank
array([ 11.87708199, 3.5299267 , 0.52876389]), # singular values
2.2204460492503131e-14) # conditioning threshold
返回的残差值是拟合误差的平方和,不确定是否是您要得到的结果
The residual value returned is the sum of the squares of the fit errors, not sure if this is what you are after:
>>> np.sum((np.polyval(np.polyfit(x, y, 2), x) - y)**2)
7.1926072073491056
在1.7版中,还有一个cov
关键字将返回系数的协方差矩阵,您可以用它来计算拟合系数本身的不确定性.
In version 1.7 there is also a cov
keyword that will return the covariance matrix for your coefficients, which you could use to calculate the uncertainty of the fit coefficients themselves.
这篇关于numpy.polyfit有什么错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文