Use non-linear least squares to fit a function, f, to data.
Assumes ydata = f(xdata, *params) + eps
Parameters: | f : callable
xdata : An M-length sequence or an (k,M)-shaped array
ydata : M-length sequence
p0 : None, scalar, or N-length sequence
sigma : None or M-length sequence, optional
absolute_sigma : bool, optional
|
---|---|
Returns: | popt : array
pcov : 2d array
|
See also
Notes
The algorithm uses the Levenberg-Marquardt algorithm through leastsq. Additional keyword arguments are passed directly to that algorithm.
Examples
>>> import numpy as np
>>> from scipy.optimize import curve_fit
>>> def func(x, a, b, c):
... return a * np.exp(-b * x) + c
>>> xdata = np.linspace(0, 4, 50)
>>> y = func(xdata, 2.5, 1.3, 0.5)
>>> ydata = y + 0.2 * np.random.normal(size=len(xdata))
>>> popt, pcov = curve_fit(func, xdata, ydata)