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

lmfit extract fit statistics parameters after fitting

这是一个关于从 lmfit fit_report()(1) 对象

中提取拟合统计信息的问题

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

我正在尝试将 Fit Statistics 部分中的所有数量提取为单独的变量。

例如。要提取 model 参数,我们可以使用(根据 1,2):

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

但是,这只是给出了模型参数;它没有给出拟合统计参数,这些参数也很有用。我似乎无法在文档中找到它。

是否有类似的方法分别提取拟合统计参数(chi-squarereduced chi-squarefunction evals等)?

result 包含所有拟合统计数据。可以得到需要的参数如下图

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

是的,很抱歉在 0.9.6 版本中无意中关闭了 Model.fit_report() 中适合度统计的报告。这已在 github 主仓库中修复。

如 user1753919 所示,您可以获得这些单独的值。 ModelResult 的这些属性记录在 https://lmfit.github.io/lmfit-py/model.html#modelresult-attributes