The Fitting Module
- qexpy.fitting.fit(*args, **kwargs)[source]
Perform a fit to a data set
The fit function can be called on an XYDataSet object, or two arrays or MeasurementArray objects. QExPy provides 5 builtin fit models, which includes linear fit, quadratic fit, general polynomial fit, gaussian fit, and exponential fit. The user can also pass in a custom function they wish to fit their dataset on. For non-polynomial fit functions, the user would usually need to pass in an array of guesses for the parameters.
- Parameters:
*args – An XYDataSet object or two arrays to be fitted.
- Keyword Arguments:
model – the fit model given as the string or enum representation of a pre-set model or a custom callable function with parameters. Available pre-set models include: “linear”, “quadratic”, “polynomial”, “exponential”, “gaussian”
xrange (tuple|list) – a pair of numbers indicating the domain of the function
degrees (int) – the degree of the polynomial if polynomial fit were chosen
parguess (list) – initial guess for the parameters
parnames (list) – the names of each parameter
parunits (list) – the units for each parameter
dataset – the XYDataSet instance to fit on
xdata – the x-data of the fit
ydata – the y-data of the fit
xerr – the uncertainty on the xdata
yerr – the uncertainty on the ydata
- Returns:
the result of the fit
- Return type:
See also
The XYFitResult Class
- XYFitResult.dataset
The dataset used for this fit
- Type:
dts.XYDataSet
- XYFitResult.fit_function
The function that fits to this data set
- Type:
Callable
- XYFitResult.params
The fit parameters of the fit function
- Type:
List[dt.ExperimentalValue]
- XYFitResult.residuals
The residuals of the fit
- Type:
dts.ExperimentalValueArray
- XYFitResult.chi_squared
The goodness of fit represented as chi^2
- Type:
dt.ExperimentalValue
- XYFitResult.ndof
The degree of freedom of this fit function
- Type:
int
- XYFitResult.xrange
The xrange of the fit
- Type:
tuple