Session Ready
Exercise

Prediction with log transforms

The code provided in the editor shows two models of used car prices versus mileage and age, one with a logarithmic transform of price. In this exercise, you'll compare the models' mean square errors.

When you build a model with a logarithmically transformed response, the usual way of calculating prediction error will produce the error in the logarithm, not the error in the original value. You'll see how to use the exp() function to "undo" the logarithm so that you can compare the price predicted rather than the logarithm of the price.

Instructions
100 XP
  • Train the two models as shown in the editor.
  • Calculate the mean square error of model_1.
  • Use the exponential function (exp()) to translate the model output from log price into the original scale of price.
  • Calculate the mean square error on price for model_2.
  • Which model produces the better predictions?