Python估计数据拟合后的标准差

2024-10-01 11:32:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用ipython--pylab将数据集拟合到超极化方程中: y=ax/(b+x)

下面是我的python代码:

from scipy import optimize as opti
import numpy as np
from pandas import DataFrame

x = np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.8])
y = np.array([0.375, 0.466, 0.509, 0.520, 0.525, 0.536, 0.541])
y_stdev = np.array([0.025, 0.016, 0.009, 0.009, 0.025, 0.019])

def func(x, a, b):
   return a*x / (b + x)

popt, pcov = opti.curve_fit(func, x, y)
print(popt)
print("a = ", popt.ix[0])
print("b = ", popt.ix[1])

ab的值应在popt参数内。我想问的是,将数据集拟合到func(x,a,b)时,会推断出ab的值,那么,我们如何估计a和b的标准差? 谢谢您。在


Tags: 数据fromimportasipythonnparrayfunc
1条回答
网友
1楼 · 发布于 2024-10-01 11:32:04

就在docs

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))...

相关问题 更多 >