pybaselines.Baseline2D.quant_reg
- Baseline2D.quant_reg(data, poly_order=2, quantile=0.05, tol=1e-06, max_iter=250, weights=None, eps=None, return_coef=False, max_cross=None)[source]
Approximates the baseline of the data using quantile regression.
- Parameters:
- dataarray_like, shape (M, N)
The y-values of the measured data.
- poly_order
intor sequence[int,int], optional The polynomial orders for x and z. If a single value, will use that for both x and z. Default is 2.
- quantile
float, optional The quantile at which to fit the baseline. Default is 0.05.
- tol
float, optional The exit criteria. Default is 1e-6. For extreme quantiles (quantile < 0.01 or quantile > 0.99), may need to use a lower value to get a good fit.
- max_iter
int, optional The maximum number of iterations. Default is 250. For extreme quantiles (quantile < 0.01 or quantile > 0.99), may need to use a higher value to ensure convergence.
- weightsarray_like, shape (M, N), optional
The weighting array. If None (default), then will be an array with shape equal to (M, N) and all values set to 1.
- eps
float, optional A small value added to the square of the residual to prevent dividing by 0. Default is None, which uses the square of the maximum-absolute-value of the fit each iteration multiplied by 1e-6.
- return_coefbool, optional
If True, will convert the polynomial coefficients for the fit baseline to a form that fits the x and z values and return them in the params dictionary. Default is False, since the conversion takes time.
- max_cross
int, optional The maximum degree for the cross terms. For example, if max_cross is 1, then x z**2, x**2 z, and x**2 z**2 would all be set to 0. Default is None, which does not limit the cross terms.
- Returns:
- baseline
numpy.ndarray, shape (M, N) The calculated baseline.
- params
dict A dictionary with the following items:
- 'weights': numpy.ndarray, shape (M, N)
The weight array used for fitting the data.
- 'tol_history': numpy.ndarray
An array containing the calculated tolerance values for each iteration. The length of the array is the number of iterations completed. If the last value in the array is greater than the input tol value, then the function did not converge.
- 'coef': numpy.ndarray, shape (
poly_order[0] + 1,poly_order[1] + 1) Only if return_coef is True. The array of polynomial parameters for the baseline, in increasing order. Can be used to create a polynomial using
numpy.polynomial.polynomial.polyval2d().
- 'coef': numpy.ndarray, shape (
- baseline
- Raises:
ValueErrorRaised if quantile is not between 0 and 1.
Notes
Application of quantile regression for baseline fitting ss described in [1].
Performs quantile regression using iteratively reweighted least squares (IRLS) as described in [2].
References
[1]Komsta, Ł. Comparison of Several Methods of Chromatographic Baseline Removal with a New Approach Based on Quantile Regression. Chromatographia, 2011, 73, 721-731.
[2]Schnabel, S., et al. Simultaneous estimation of quantile curves using quantile sheets. AStA Advances in Statistical Analysis, 2013, 97, 77-87.