Home Knowledge Base Log Transformation

Log Transformation is a data preprocessing technique that applies the logarithm function to compress large values and spread out small values — converting right-skewed distributions (income, house prices, website traffic) into approximately normal distributions that linear models, neural networks, and statistical tests assume, while stabilizing variance so that predictions are equally reliable across the range rather than more accurate for small values and wildly inaccurate for large values.

What Is Log Transformation?

When to Use Log Transformation

Data TypeSkewExampleEffect of Log
Income/SalaryHeavy right skew$30K, $50K, $80K, $500K, $10MCompresses outlier salaries
House PricesModerate right skew$200K, $400K, $2M, $50MMakes distribution more symmetric
Website TrafficHeavy right skew10, 50, 200, 1M page viewsEqualizes small and large sites
Count DataRight skew0, 1, 3, 5, 500 retweetsSpreads low counts, compresses high
Elapsed TimeRight skew1s, 5s, 30s, 600s response timesNormalizes response time distribution

Before and After Example

Original SalaryLog(Salary + 1)Effect
$30,00010.31Slightly compressed
$50,00010.82Slightly compressed
$80,00011.29Slightly compressed
$500,00013.12Moderately compressed
$10,000,00016.12Heavily compressed

The range went from $30K-$10M (333× ratio) to 10.31-16.12 (1.56× ratio) — dramatically reducing the impact of extreme values.

Python Implementation

import numpy as np
import pandas as pd

# Log1p (handles zeros safely)
df["log_salary"] = np.log1p(df["salary"])

# Reverse: expm1 to get back original scale
df["original"] = np.expm1(df["log_salary"])

Common Alternatives

TransformFormulaWhen to Use
Log (ln)$log(x + 1)$Standard for right-skewed data
Square Root$sqrt{x}$Less aggressive compression than log
Box-CoxFinds optimal λWhen the best transform is unknown
Yeo-JohnsonModified Box-CoxWorks with negative values (Box-Cox requires positive)

Log Transformation is the standard preprocessing technique for right-skewed data — normalizing distributions that violate model assumptions, stabilizing variance across the value range, and compressing extreme outliers, making it one of the first transformations to try when features span multiple orders of magnitude.

log transformskewnormalize

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.