# How to get the actual mean absolute error in cross validation after transforming the target variable y?

For a target variable y, it is transformed using np.log1p. Then a random forest regression model is trained using the transformed y.

Then I tried to use cross_val_score in sklearn to compute the neg_mean_absolute_error. The mean of the returned scores is -0.17. Should I convert it back by using np.emp1(0.17)?

But the error is too small. As I am predicting housing price. The error should be much larger than this.

• If I understand correctly, you should first back-transform the results of the regression and then calculate both the price errors and their absolute mean. – James Phillips Dec 28 '19 at 11:27

You should be able to calculate the mean absolute error (MAE) using just very basic functions in Python. If y is your target variable and you used your transformed target variable y_trans to train the model, you will get a transformed outcome variable out_trans. To get a meaningful MAE, in housing price e.g., you would have to transform your outcome variable,out_trans, using the inverse transformation function you used in y. Note that this is different from transforming the MAE itself, as you suggested. After that, the MAE is just the mean of the differences between y and out, in module:
import numpy as np

• Thank you! By using your method, I can compute the MAE for the trained model. But what if I want to compute the average MAE in cross validation? Can I do that in cross_val_score? Or I need to use the pipeline in sklearn – JOHN Dec 29 '19 at 4:29