waltlabtools.core.regress¶
- regress(model, x, y, use_inverse=False, weights='1/y^2', p0=None, bounds=None, method=None)[source]¶
Performs a (nonlinear) regression and return coefficients.
- Parameters
model (
Model
orstr
) -- The functional model to use. Should be a validModel
object or a string referring to a built-inModel
.x (array-like) -- The independent variable, e.g., concentration.
y (array-like) -- The dependent variable, e.g., fluorescence.
use_inverse (
bool
, default False) -- Shouldx
be regressed as a function ofy
instead?weights (
str
or array-like, default "1/y^2") -- Weights to be used. If array-like, should be the same size as x and y. Otherwise, can be one of the following:"1/y^2" : Inverse-squared (1/y^2) weighting.
"1" : Equal weighting for all data points.
Other strings raise a
NotImplementedError
.p0 (array-like, optional) -- Initial guess for the parameters. If provided, must have the same length as the number of parameters. 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).bounds (2-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 scipy.optimize.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.
- Returns
popt (array) -- Optimal values for the parameters so that the sum of the squared residuals is minimized.
See also
scipy.optimize.curve_fit
backend function used by
regress