拟合后lmfit提取拟合统计参数

ede*_*esz 2 python curve-fitting lmfit

这是关于从lmfit fit_report()1)对象提取拟合统计信息的问题

lmfit示例中,返回以下部分输出:

[[Model]]
    Model(gaussian)
[[Fit Statistics]]
    # function evals   = 31
    # data points      = 101
    # variables        = 3
    chi-square         = 3.409
    reduced chi-square = 0.035
    Akaike info crit   = -336.264
    Bayesian info crit = -328.418
.
.
.
.
.
.
Run Code Online (Sandbox Code Playgroud)

我试图提取该Fit Statistics部分中的所有数量作为单独的变量。

例如。提取模型参数,我们可以使用(每12):

for key in fit.params:
    print(key, "=", fit.params[key].value, "+/-", fit.params[key].stderr)
Run Code Online (Sandbox Code Playgroud)

但是,这仅给出了模型参数。它没有提供拟合统计参数,这也很有用。我似乎在文档中找不到此内容。

有没有类似的方式来提取拟合统计参数(chi-squarereduced chi-squarefunction evals分别,等等)?

pla*_*360 5

结果包含所有适合的统计信息。您可以获取所需的参数,如下所示

result = gmodel.fit(y, x=x, amp=5, cen=5, wid=1)
# print number of function efvals
print result.nfev
# print number of data points
print result.ndata
# print number of variables
print result.nvarys
# chi-sqr
print result.chisqr
# reduce chi-sqr
print result.redchi
#Akaike info crit
print result.aic
#Bayesian info crit
print result.bic
Run Code Online (Sandbox Code Playgroud)

  • 我查看了 fit_report() 的代码 (https://github.com/lmfit/lmfit-py/blob/master/lmfit/printfuncs.py) 并且能够看到它是如何获取所有这些参数的。或者,您可以使用 dir(result) 查看所有属性。此外,如果您使用的是 ipython notebook,则可以输入“result”。然后按 Tab 键,会有一个下拉菜单将显示所有属性。 (2认同)