Doug Fir Doug Fir - 1 month ago 7
R Question

When predicting using model with log(target) do I have to make any changes to predict function?

I have a dataset where the target variable is skewed left. When I plot a histogram of the log of this variable it's a nice, normal looking distribution. So I believe I should log transform it?

I tried that in my_model below. But when I evaluated it by looking at Mean Absolute Error I found that it under performed against the non log transformed version.

my_model <- lm(target ~ ,var1+var2+var3, data=ptrain)
my_model_log <- lm(log(target) ~ ,var1+var2+var3, data=ptrain)

my_predictions <- predict(my_model_log, interval="prediction", newdata=test_submission)


my_predictions showed lower performance when using the log model.

Is this expected? Is there a parameter I should add to
predict()
to tell it that the target has bee log transformed before making the prediction?

42- 42-
Answer

If you predict(), it will return an estimate for log (target). If you want an estimate for target you need to apply the inverse transformation, exp(), to the predictions. The prediction interval may have interesting properties.

Comments