ladfit

tayph.ladfit(x, y, t=None)[source] [edit on github]

This is a wrapper for LAD regression with sklego, implemented in a way such that it returns the linear coefficients a,b from y=ax+b. x and y need to be one-dimensional arrays.

LADRegression accepts multi-dimensional arrays but that is for doing multivariate linear regression, not independent regression for different datasets y defined on the same grid x. So I could not get this to work for a multidimensional Y array without looping.

The algoritm returns the model coefficients [a,b], either with 2 or mx2 elements. This behavior is made to match np.polyfit.

Doing a linear fit with ladfit(x,y.T) is cognate with np.polyfit(x,y,1). The extra transpose is there so that ladfit works intuitively on an n x m frame for which the x axis is horizontal (e.g. a spectral order).

Set the parameter t to a threshold number of sigma values that are considered outliers. The algorithm will do an initial fit, flag residuals that are t*sigma away from 0.0 as outliers, mask these, and do the fit again. Doing this will return a second variable that has the same shape as y, filled with 1.0s for values that are good, and 0.0s for outliers. This can be used as an outlier mask.

If you want to rip this out of tayph for your own purposes, all you need to remove is the test functions.

Parameters
xnp.ndarray

A 1D array with x values.

ynp.ndarray

A 1D or 2D array containing dependent variable.