What you will be able to do
- Explain why a model trained on a log-transformed target returns predictions in log units, not original units
- Choose the inverse function that matches the forward transform: exp for log, expm1 for log1p
- Compute RMSE and MAE on predictions and actuals that share the same original scale
- Recognise invalid metric comparisons and misleading displays caused by un-inverted predictions
Key concept
Inverting a log-target prediction — A regression model fitted on log(y) learns to predict log(y), so every number it outputs is a logarithm. To get back to original units for metrics or for people, apply the exact inverse of the forward transform (exp for log, expm1 for log1p) to the predictions, and compare them against actuals on that same original scale.
1.A log-target model predicts in log units
A regression model only ever learns the target you hand it. Home prices, customer lifetime value and shipping costs are often right-skewed, with a long tail of very large values, so a common fix is to train on the logarithm of the target. The reasons for doing that are covered in when a log transform is appropriate. The consequence is the subject here: once the label column holds logs, the model's prediction column holds logs too.
The model has no idea it is predicting dollars. Suppose you train on the natural log of sale price. A house worth $160,000 becomes a label of about 11.98, and a house worth $1,000,000 becomes about 13.82. When the fitted model scores a new house and returns 12.0, that is not twelve dollars, and it is not twelve thousand. It is a point on the natural-log scale, and you only get a price back by undoing the transform.
"Log" in this setting almost always means the natural logarithm, base e. That matters because the inverse has to use the same base: e raised to the prediction. Nothing in the model, the pipeline or the evaluator applies that inverse for you unless you build it in, so the log-scale numbers flow into whatever comes next. That might be a metric, a table or a dashboard.
Checkpoint 1 of 7· Check yourself
A team trains a regression model on ln(sale_price). There are no other steps in the pipeline. For a new house, the prediction column shows 12.0. What must they do before they show this value to anyone as a price?
The model learned ln(price), so its output is a natural-log value, and nothing inverts it unless you build that step in. The inverse of ln uses the same base: e raised to the prediction, which is exp. expm1 undoes log1p, not ln, and base 10 is the wrong base.
“Returns e to the power of expr.”Source: docs.databricks.com
2.Match the inverse to the forward transform
The inverse must be the exact mirror of the forward step. A target built with plain log (natural log, ln) is undone with exp. A target built with log1p, meaning log(1 + y) and chosen because it handles zeros, is undone with expm1, meaning e^x − 1. A base-10 log is undone with pow(10, x). In NumPy these pairs are np.log/np.exp and np.log1p/np.expm1. Spark SQL and PySpark have functions with the same names.
| Forward transform | What it computes | Inverse to apply to predictions |
|---|---|---|
| ln(col) or log(col) | natural log of y | exp(col): e to the power of the prediction |
| log1p(col) | natural log of (y + 1) | expm1(col): e to the power of the prediction, minus one |
| log10(col) | logarithm of y in Base 10 | pow(10, prediction) |
Using the wrong member of the pair gives a systematic error. If the target went through log1p, then exp(prediction) returns y + 1 rather than y, so every prediction is one unit too high. On house prices that is a single dollar and easy to miss. On a target like daily support tickets, where many true values are 0 to 5, being one unit high on every row wrecks MAE. The fix costs nothing: look at how the label column was built and invert with the matching function.
from pyspark.sql import functions as dbf
df = spark.sql("SELECT id AS value FROM RANGE(5)")
df.select("*", dbf.expm1(df.value)).show()Predictions and actuals have to end up on the same scale. If your evaluation DataFrame still holds the logged label, invert it with the same function you use on the predictions. If it holds the untouched original column, use that as it is. Both routes give identical numbers, because expm1(log1p(y)) is y. The error is mixing them: inverted predictions against logged actuals, or raw log predictions against dollar actuals.
Checkpoint 2 of 7· Fill the gap
A label column was built with log1p, so the model's predictions are log1p values. This PySpark sample applies the inverse to a column. Which function fills the blank?
from pyspark.sql import functions as dbf
df = spark.sql("SELECT id AS value FROM RANGE(5)")
df.select("*", dbf. ? (df.value)).show()log1p computes ln(1 + y), so its exact inverse is expm1, which is e^x − 1. Using exp would return y + 1 and make every prediction one unit too high. log1p and ln go the forward way, so they would take the log a second time instead of undoing it.
Source: docs.databricks.com3.Compute metrics in original units
An error metric takes the units of the values you feed it. RMSE and MAE, covered in regression metrics, are computed from differences between actual and predicted values. Feed them log values and RMSE comes out in log units. An RMSE of 0.18 on log price roughly means predictions are typically off by about 18 percent. That is a relative measure, not a dollar amount, and a stakeholder who reads it as "$0.18 off" or "$180 off" has been misled.
errors <- select(predictions, predictions$price, predictions$prediction, alias(predictions$price - predictions$prediction, "error"))
display(errors)
# Calculate RMSE
head(select(errors, alias(sqrt(sum(errors$error^2 , na.rm = TRUE) / nrow(errors)), "RMSE")))The arithmetic above is correct, and it still reports the wrong thing if prediction holds logs. Add a step before it that replaces the prediction column with its inverse, for example withColumn("prediction", expm1("prediction")), and that price is the original column. Only then is the reported RMSE in dollars.
You can't tell from these numbers. 0.21 is in log-dollars and 38,500 is in dollars, so comparing them is like comparing a temperature in Celsius with one in Fahrenheit. Invert both models' predictions to dollars, compute both RMSEs against the same original-scale actuals, and then compare.
Comparisons across scales are where this goes wrong most often. Log-scale errors are usually numerically much smaller than dollar-scale errors, but that is a property of the units, not of the models. Swapping the metric does not fix a units mismatch either. R² computed on the log scale for one model and on the dollar scale for another still describes two different prediction problems. The rule is to put every candidate on the same scale, preferably original units, before ranking them.
Checkpoint 3 of 7· Check yourself
A model was trained on log1p(price). The analyst computed RMSE = 0.18 directly from the raw prediction column and the logged label. A manager asks for the typical error in dollars. What is the correct next step?
RMSE takes its units from the values it receives, so 0.18 is in log units. To get dollars, invert the predictions with the function that matches log1p, which is expm1. Then compute RMSE again against actuals in original units. Inverting the finished metric does not give a dollar RMSE, and a log-scale R² still describes a different prediction problem.
“errors <- select(predictions, predictions$price, predictions$prediction, alias(predictions$price - predictions$prediction, "error"))”Source: docs.databricks.com
Checkpoint 4 of 7· Exam question
A data scientist trained a regression model to predict home sale prices by first transforming the target using np.log1p(price), since the raw distribution was heavily right-skewed. The model's predictions come out in this transformed scale. Before reporting RMSE to stakeholders in dollar terms, what should the data scientist do?
Correct answer: A — Apply np.expm1 to both the predicted and actual log-transformed values to reverse the transform, then compute RMSE on the resulting dollar-scale numbers for stakeholders.
- A. This is correct:
np.expm1is the exact inverse ofnp.log1p, so applying it to both the predictions and the actuals converts them back to dollars before RMSE is computed, giving an error figure stakeholders can interpret in real price terms. - B. Reporting the error on the log-transformed scale gives a number in log-dollar units that does not correspond to any real price difference, which makes it meaningless to a business audience expecting dollar figures.
- C. Using
np.expinstead ofnp.expm1produces predictions that are all offset by roughly one dollar relative to the correct inverse, and mixing exponentiated predictions with raw actuals still leaves the units inconsistent with how the model was trained. - D. Multiplying by the mean of the raw target has no mathematical relationship to undoing a log transform and would produce an arbitrary, incorrect approximation rather than a valid dollar-scale error metric.
Checkpoint 5 of 7· Exam question
Two candidate regression models were trained to predict a heavily skewed shipping-cost target after log-transforming it. During evaluation, one engineer reports Model A's RMSE computed directly on the log-transformed predictions, while another reports Model B's RMSE after exponentiating predictions back to the original dollar scale. The team wants to pick the better model using these two RMSE values. What is the problem with this comparison?
Correct answer: A — The two RMSE values are computed in different units, log-dollars versus dollars, and cannot be compared directly; both models must be exponentiated to the same scale first.
- A. This is correct: RMSE computed on log-transformed values and RMSE computed on exponentiated, original-scale values are expressed in different units, so a fair comparison requires putting both models' errors on the same scale first.
- B. RMSE remains a usable metric for skewed targets as long as it is computed consistently in the same units for every model; the issue here is inconsistent units between the two reports, not an inherent flaw in RMSE itself.
- C. Log-scale errors are not guaranteed to be smaller in a way that predicts the original-scale ranking, so assuming Model A is better without exponentiating Model A's predictions is an unjustified conclusion.
- D. Using the same transform during training does not make evaluation metrics comparable when one model's error is reported before exponentiation and the other's is reported after; the units still differ between the two reports.
Sources5
4.Interpreting predictions for people
Anything shown to a person needs to be in units that person understands. A dashboard of expected lifetime value per customer that displays 6.9, 7.4 and 8.1 is not showing dollars. Those are logs of roughly $990, $1,640 and $3,300. The ordering of customers survives the log transform, because log is monotonic. The values do not, and the gaps between them are badly compressed: a difference of 1.2 on the log scale is more than a threefold difference in dollars.
Other ways of tidying up log predictions do not turn them into dollars. Dividing by the standard deviation of the training target produces a unitless number. Rounding to the nearest integer leaves a log value with fewer decimals. Multiplying by the training mean mixes a logarithm with a dollar amount. The only operation that recovers original units is the inverse of the forward transform: exp for a natural log and expm1 for log1p.
Checkpoint 6 of 7· Check yourself
On a customer lifetime value dashboard, the expected-value column shows 6.9, 7.4 and 8.1. These come from a model trained on ln(lifetime_value). What should be done to these numbers before the dashboard shows them as dollar amounts?
The model learned ln(value), so it outputs natural-log values. Only the inverse, e raised to the prediction, recovers dollars. The ranking is preserved, but the values and the gaps between them are still logs. Dividing by the standard deviation gives a unitless number, and multiplying by the training mean mixes a logarithm with a dollar amount.
“Returns e to the power of expr.”Source: docs.databricks.com
Checkpoint 7 of 7· Exam question
A machine learning pipeline predicts subscription lifetime value (LTV) after applying a log transformation to the training target to reduce skew. A product manager asks the data science team to add the model's raw predictions directly to a customer-facing dashboard showing expected dollar value per customer. What should the team do before displaying these numbers?
Correct answer: A — Exponentiate the model's log-scale predictions using the inverse of whatever transform was applied during training, so the dashboard shows dollar values directly.
- A. This is correct: reversing the training-time log transform with its matching inverse function converts the predictions back into dollar units, which is what a dashboard labeled as showing expected dollar value requires.
- B. Preserving rank order does not satisfy the dashboard's requirement, since the request is for dollar-denominated values a product manager can read directly, not just a relative ordering of customers.
- C. Dividing by the standard deviation of the target is a standardization operation, not an inverse of a log transform, and would produce values with no meaningful dollar interpretation.
- D. Rounding a log-scale number does not convert it into dollars; log-transformed values are numerically much smaller than the original target and would badly understate the true expected value.
Sources
(8)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“Returns the natural logarithm (base e) of expr.”
↩︎ A log-target model predicts in log units - 2.https://scikit-learn.org/stable/modules/compose.htmlSecondary source
“TransformedTargetRegressor deals with transforming the target (i.e. log-transform y).”
↩︎ A log-target model predicts in log units - 3.
“Computes the natural logarithm of the given value plus one.”
↩︎ Match the inverse to the forward transform - 4.
“Computes the exponential of the given value minus one.”
↩︎ Match the inverse to the forward transform“Computes the exponential of the given value minus one.”
↩︎ Exam trap 1“Computes the exponential of the given value minus one.”
↩︎ Prediction - 5.
“alias(predictions$price - predictions$prediction, "error")”
↩︎ Compute metrics in original units“alias(predictions$price - predictions$prediction, "error")”
↩︎ Exam trap 2“errors <- select(predictions, predictions$price, predictions$prediction, alias(predictions$price - predictions$prediction, "error"))”
↩︎ Checkpoint - 6.
“Returns e to the power of expr.”
↩︎ Interpreting predictions for people“Returns e to the power of expr.”
↩︎ Key concept“Returns e to the power of expr.”
↩︎ Exam trap 3“Returns e to the power of expr.”
↩︎ Checkpoint - 7.https://scikit-learn.org/stable/modules/model_evaluation.htmlSecondary source
“Typical examples are the mean (expected value), the median or a quantile of the response variable”
↩︎ Interpreting predictions for people
Also cited
“Computes the exponential of the given value.”
↩︎ Exam trap 4