Machine Learning Associate ยท Exploring and preparing data
Log scale transformation
Scenarios where a log transformation is appropriate (right-skewed, multiplicative spread, positive values only) and its limits.
Key points
- Strictly positive, right-skewed data spanning orders of magnitude (prices, incomes, counts): log pulls in the long tail, turns multiplicative effects additive.
- Zeros need log1p, i.e. log(1 + x); negatives cannot be logged.
- No help for left-skewed data; mostly unnecessary for tree models (order is kept).
- Logged target: exponentiate predictions (exp, or expm1 for log1p) before metrics or reporting in original units.
Practice questions
Which values make a plain natural-log transform invalid?
- Zero and negative values
- Values larger than 1000
- Values with decimals
- Values that repeat
Show answer
Answer: A. Zero and negative values
The logarithm is defined only for positive numbers; zero and negatives need a different treatment such as log1p (for zeros) or another transform.
Which scenarios fit a log transformation?
- A strictly positive, right-skewed income column
- Web response sizes ranging from bytes to gigabytes
- A non-negative count column with many zeros, using log1p
- A left-skewed score column capped at 100
- Profit and loss values that are often negative
Show answer
Answer: A. A strictly positive, right-skewed income column, B. Web response sizes ranging from bytes to gigabytes, C. A non-negative count column with many zeros, using log1p
Positive right-skewed data and values spanning orders of magnitude fit; zeros need log1p. Left-skewed data would get worse, and negative values cannot be logged.
True or false: log-transforming a feature changes the order of its values, so a decision tree will find different splits.
Show answer
Answer: False
False. Log is monotonic, so the order of values is unchanged and a tree can make equivalent splits. Log helps mainly linear and distance-based models.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
