The standard sklearn linear regression class finds an approximated linear relationship between variate and covariates that minimises the mean squared error (MSE). Specifically, let N be the number of observations and let us ignore the intercept for simplicity. Let yj be the variate value of the j-th observation and x1,j,…,xn,j be the values of the n covariates of the j-th observation. The linear relationship is of the form
where the coefficients β1,…,βn are given by
I now wish to find the coefficients that minimise the mean absolute deviation (MAD) instead of the mean squared error. Namely, I want the coefficients given by
I understand that, in sharp contrast to the MSE case, the lack of differentiability of the absolute value function at 0 implies there is no analytic solution for the MAD case. But the latter is still a convex optimisation problem, and, according to this answer, it can be easily solved by means of linear programming.
Is it possible to implement this linear regression in sklearn? What about using other statistics toolkits?
The expected MAD is minimized by the median of the distribution (Hanley, 2001, The American Statistician; see also Why does minimizing the MAE lead to forecasting the median and not the mean?). Therefore, you are looking for a model that will yield the conditional median, instead of the conditional mean.
This is a special case of quantile-regression, specifically for the 50% quantile. Roger Koenker is the main guru for quantile regression; see in particular his book Quantile Regression.