Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Training Linear Models with MAE using sklearn in Python

I'm currently trying to train a linear model using sklearn in python but not with mean squared error (MSE) as error measure - but with mean absolute error (MAE). I specificially need a linear model with MAE as requirement from my professor at university.

I've looked into sklearn.linear_model.LinearRegression which since it is an OLS regressor does not provide alternative error measures.

Hence, I checked the other available regressors and stumbled upon sklearn.linear_model.HuberRegressor and sklearn.linear_model.SGDRegressor. They both mention MAE as part of their error measures - but do not seem to provide simple MAE. Is there a way to choose the parameters for one of those regressors so that the resulting error measure is a simple MAE? Or is there another regressor in sklearn which I've overlooked?

Alternatively, is there another (easy to use) python 3.X package which provides what I need?

Thanks for your help!

like image 276
Lennart Avatar asked May 17 '18 13:05

Lennart


1 Answers

In SGD, if you use 'epsilon_insensitive' with epsilon=0 it should work as if you used MAE.

You could also take a look at statsmodels quantile regression (using MAE is also called median regression, and median is a quantile).

like image 161
Jakub Bartczuk Avatar answered Oct 11 '22 17:10

Jakub Bartczuk