CertSafari
    Databricks Certified Machine Learning Associate· Lessons

    Domain 3 · Lesson 41/48

    Exponentiating log-transformed predictions before metrics

    Identify the need to exponentiate log-transformed variables before calculating evaluation metrics or interpreting predictions

    13 min read
    2.07% of exam
    8 sources
    Published 22 Oct 2026
    Docs as of 30 Sep 2026

    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?

    Sources12

    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 on the target and the function that reverses it
    Forward transformWhat it computesInverse to apply to predictions
    ln(col) or log(col)natural log of yexp(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 10pow(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.

    PySpark expm1, the inverse of log1p, applied to a columnpython
    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()

    Sources34

    3.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.

    An RMSE computed from price minus prediction. The result is in price units only if both columns are in price units.r
    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.

    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?

    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?

    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?

    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?

    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?

    Sources67

    Sources

    (8)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 2.
      “TransformedTargetRegressor deals with transforming the target (i.e. log-transform y).”
      ↩︎ A log-target model predicts in log units
    2. 3.
      “Computes the natural logarithm of the given value plus one.”
      ↩︎ Match the inverse to the forward transform
    3. 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
    4. 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
    5. 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
    6. 7.
      “Typical examples are the mean (expected value), the median or a quantile of the response variable”
      ↩︎ Interpreting predictions for people

    Also cited

    Spotted a mistake, or was something unclear? Tell us.