python optimize_python多元拟合问题

貌似关于多元拟合的使用没有太多文章进行讲解。

首先给出数据集:

v2-d256c21d9c2a14b98aac11e23ea7520d_b.jpg
数据集

目标函数:

在python中,我们使用scipy.optimize库中的curve_fit,首先给出其官方文档中一些比较重要的参数简介:

Parameters
fcallable
The model function, f(x, …). It must take the independent variable as the first argument and the parameters to fit as separate remaining arguments.
xdataarray_like or object
The independent variable where the data is measured. Should usually be an M-length sequence or an (k,M)-shaped array for functions with k predictors, but can actually be any object.
ydataarray_like
The dependent data, a length M array - nominally f(xdata, ...).
p0array_like, optional
Initial guess for the parameters (length N). If None, then the initial values will all be 1 (if the number of parameters for the function can be determined using introspection, otherwise a ValueError is raised).
bounds2-tuple of array_like, optional
Lower and upper bounds on parameters. Defaults to no bounds. Each element of the tuple must be either an array with the length equal to the number of parameters, or a scalar (in which case the bound is taken to be the same for all parameters). Use np.inf with an appropriate sign to disable bounds on all or some parameters.
method{‘lm’, ‘trf’, ‘dogbox’}, optional
Method to use for optimization. See least_squares for more details. Default is ‘lm’ for unconstrained problems and ‘trf’ if bounds are provided. The method ‘lm’ won’t work when the number of observations is less than the number of variables, use ‘trf’ or ‘dogbox’ in this case.
New in version 0.17.
Returns
poptarray
Optimal values for the parameters so that the sum of the squared residuals of f(xdata, *popt) - ydata is minimized.
pcov2-D 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)).
How the sigma parameter affects the estimated covariance depends on absolute_sigma argument, as described above.
If the Jacobian matrix at the solution doesn’t have a full rank, then ‘lm’ method returns a matrix filled with np.inf, on the other hand ‘trf’ and ‘dogbox’ methods use Moore-Penrose pseudoinverse to compute the covariance matrix.

其中,fcallable是我们需要拟合函数原型,xdataarray是我们的输入,注意在这里,输入矩阵的形状为 k*M(k为参数个数),ydataarray是我们的输出。

p_0array_like、bounds2-tuple of array_like、method是可选参数,分别是初始值、边界和回归算法,当我们需要设置边界时,算法只能选择为'trf'和'dogbox'。

LM是在目标函数中,加入一个阻尼项,在接近最终结果是,可以活得二次收敛速度,和高斯牛顿法类似。而dogbox算法,需要判断移动相关步长之后,是否仍在信赖域中。

最后给出,拟合之后的曲线:

v2-6948aff2303392e50efaafb6d2e7aae8_b.jpg
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值