繁体   English   中英

在 SciPy LeastSq 中获取变量以使用它们

[英]Get Variables in SciPy LeastSq to use them

我需要为每个 minimum_sq 运行中创建的每个参数获取拟合结果。 谁能指导我从 SciPy LeastSq 中的函数参数推断的参数名称?

** 好消息! 使用lmfit这么棒的包!**

from scipy.optimize import least_squares
from matplotlib.pylab import plt
import numpy as np
from numpy import exp, linspace, random
from lmfit import Model


def gaussian(x, amp, cen, wid):
    return amp * np.exp(-(x-cen)**2 / wid)


x = linspace(-10, 10, 101)
y = gaussian(x, 2.33, 0.21, 1.51) + random.normal(0, 0.2, len(x))

gmodel = Model(gaussian)
params = gmodel.make_params()
print('parameter names: {}'.format(gmodel.param_names))
print('independent variables: {}'.format(gmodel.independent_vars))
result = gmodel.fit(y, params, x=x, amp=5, cen=5, wid=1)
print(result.fit_report())
[n many cases we might want to extract parameters and standard error estimates programatically rather than by reading the fit report][1]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM