1
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – James Phillips Dec 28 '19 at 11:27
0
$\begingroup$

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
mae = np.mean(abs(y) - abs(out))

You could of course compute the MAE with the transformed quantities, but as you said, the unit won't be that meaningful.

$\endgroup$
  • $\begingroup$ 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 $\endgroup$ – JOHN Dec 29 '19 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.