python - 我如何在 python 中使用 pcov 来获取每个参数的错误?

标签 python curve-fitting

我有一个代码并使用 curve_fit 将洛伦兹曲线和高斯曲线拟合到数据。 我需要得到每个输出参数的误差估计,所以打印了 popt 和 pcov 我知道 scipy 引用指南说明了如何使用 pcov 矩阵来查找错误,但这对我来说还不清楚,因为我是编程新手。 谢谢

最佳答案

阅读文档通常可以为此类问题提供答案。例如,curve_fit() 的文档位于 https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html说:

Returns: popt : array Optimal values for the parameters so that the sum of the squared residuals of f(xdata, *popt) - ydata is minimized

pcov : 2d array The estimated covariance of popt. The diagonals provide the variance of the parameter estimate. To compute one standard deviation errors on the parameters use perr = np.sqrt(np.diag(pcov)). How the sigma parameter affects the estimated covariance depends on absolute_sigma argument, as described above.

也就是说:使用 p_sigma = np.sqrt(np.diag(pcov))

请允许我建议,对于高斯和洛伦兹模型的曲线拟合,您可能会发现 lmfit ( https://lmfit.github.io/lmfit-py/) 很有帮助。它为这些和其他模型提供内置版本。除其他功能外,它还可以打印格式精美的报告,以适应这种包含不确定性的情况。

有关示例,请参阅 https://lmfit.github.io/lmfit-py/builtin_models.html#example-1-fit-peaked-data-to-gaussian-lorentzian-and-voigt-profiles

关于python - 我如何在 python 中使用 pcov 来获取每个参数的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43561036/

相关文章:

python - Tensorflow 对象检测 API : Custom VGG 16 model

python - 多个线程在 Python 中同时写入日志文件

嵌套字典列表的 Python 平均列表

Python:从列表的字符串元素创建变量/数据框名称

matlab - MATLAB 和卡方检验的拟合优度

excel - 如何将Excel中的数据曲线拟合为多变量多项式?

Python 和 matplotlib 绘制超出域的点,曲线拟合较差

javascript - 使用 Scrapy - JS 制作蜘蛛

python - 多边形 Blob 的中心线(二值图像)

python - 使用 numpy.polynomial.legendre 时,如何获得将输入转换为 Legendre 多项式参数的函数?