【问题标题】:lmfit extract fit statistics parameters after fittinglmfit 拟合后提取拟合统计参数
【发布时间】:2017-04-13 00:48:36
【问题描述】:

这是一个关于从lmfitfit_report()(1) 对象中提取拟合统计数据的问题

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

[[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 参数,我们可以使用 (per 1,2):

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

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

有没有类似的方法分别提取Fit Statistics参数(chi-squarereduced chi-squarefunction evals等)?

【问题讨论】:

    标签: python curve-fitting lmfit


    【解决方案1】:

    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
    

    【讨论】:

    • 谢谢,但是你是怎么知道的?有没有办法检查results对象的属性?
    • 我查看了 fit_report() 的代码 (github.com/lmfit/lmfit-py/blob/master/lmfit/printfuncs.py) 并能够看到它是如何获取所有这些参数的。或者,您可以使用 dir(result) 查看所有属性。另外,如果你使用的是 ipython notebook,你可以输入“result”。然后按tab,会出现一个下拉菜单,里面会包含所有的属性。
    • 我试过result.attributes(),但这没有用。谢谢你的帖子。这个问题得到了回答。
    【解决方案2】:

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

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

    【讨论】:

    • 嘿,谢谢你的信息。这是非常有用的。很好的链接!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-07
    • 2018-05-24
    相关资源
    最近更新 更多