2.1.9 · D1Data Preprocessing & Feature Engineering

Foundations — Log and power transformations

2,508 words11 min readBack to topic

Before you can read the parent note, you need to be able to read its symbols the way you read words. Below, every symbol is built from zero — plain meaning first, then a picture, then why the topic needs it. They are ordered so each one rests on the ones before it.


1. The number line and "spread"

Picture your data as dots dropped onto this ruler. When you have lots of numbers, they form a pile — thick where many dots land, thin where few do.

Look at the top row of the figure: the dots for house prices are jammed against the left and one lonely dot sits far to the right. That lopsided pile has a name.

Why the topic needs it. Every transformation on the parent page exists to fix skew — to turn the lopsided pile (top of figure) into a symmetric hill (bottom of figure). If you cannot see skew, none of the "why" makes sense.


2. , , and the prime mark

Picture the transformation as a machine: a dot goes in the left, a re-labelled dot comes out the right. Same dot, new address.

Why the topic needs it. Every formula (, , Box-Cox) is a recipe that turns into . Without knowing what the prime means you cannot read a single formula.


3. Powers and roots:

In the figure the horizontal axis is the original value and the vertical axis is the transformed value ; both run over the same positive numbers so you can compare a curve against the straight "do nothing" line. Follow the orange curve (): as grows, the curve bends downward, so a big jump in becomes only a small jump in — that is the squeezing. The blue line () is dead straight: no squeeze at all. The red curve () flips large down toward zero.

Why the topic needs it. Box-Cox is nothing but trying different dial settings to find the squeeze that flattens skew best. is just the dial parked at .


4. The exponential — the "constant-percent growth" curve

Why the topic needs it. The parent's key sentence is "log turns multiplicative changes into additive ones." That only makes sense once you see that skewed data was built multiplicatively by an -style process.


5. The logarithm — the exact undo of

In the figure the horizontal axis is the input and the vertical axis is the output, both on the same scale so the dashed grey line marks "input equals output". The blue exponential takes an input and climbs to a height ; the orange log takes that height on its horizontal axis and hands back the original — that mirror-across-the-diagonal is what "undo" looks like. Because the log curve rises fast then flattens, huge inputs on the right get mapped to only slightly-bigger outputs — that is the compression the topic wants.

Why the topic needs it. This single fact is why de-skews multiplicative data and why a regression coefficient on a logged feature reads as a percentage effect.


6. Variance and homoscedasticity

Left panel: the cloud of points fans out — small spread on the left, huge spread on the right (heteroscedastic). Right panel: after a log re-ruler, the band has even thickness everywhere (homoscedastic).

Why the topic needs it. Linear regression assumes equal spread. Transformations are the standard cure — in the parent's housing example the spread collapses from a standard deviation of about $2\text{M}0.7_{10}0.7$ of a "power-of-ten"). The two numbers live on different rulers — that is exactly the point: the re-ruler has turned a wild dollar-spread into a tame log-spread.


7. Limit and continuity — why Box-Cox has that funny " over "

The Box-Cox recipe has a hole at (you would divide by ). We now show why the value that fills the hole is exactly — that is not a lucky coincidence, it falls out of two facts we can picture.

Why the topic needs it. The whole reason Box-Cox writes two lines (one for , one for ) is to keep the dial's action smooth as it passes through zero. No limit ⇒ no understanding of why the log case is not arbitrary.


8. Sign cases: versus

Some data is only ever positive (prices, counts) — those live entirely on the right of the number line. Other data (temperature anomalies, profit/loss) crosses zero into negatives.

  • and Box-Cox need : the log machine has no answer for or negatives (, undefined — there is no power of that lands on a negative number).
  • Yeo-Johnson is built with separate cases for and , mirroring the positive recipe onto the negative side so the pen never lifts at zero.

Why the topic needs it. Every "which transformation?" decision on the parent page starts with the single question: does my data include zeros or negatives? That question is entirely about which side of the number line the dots live on.


Prerequisite map

Number line and dots

Skew - lopsided pile

x and x prime

Powers x to lambda

Exponential e to z

Logarithm - undoes e

Limit and continuity

Variance and equal spread

Sign cases pos vs neg

Log and Power Transformations

Read it top-down: the number line feeds everything; exponential feeds log; powers plus limits feed Box-Cox; sign cases feed Yeo-Johnson. All arrows converge on the topic.

Related vault stops once you have these: 2.1.05-Feature-Scaling (a different kind of re-ruler), 2.1.08-Handling-Outliers (transformations tame outliers instead of deleting them), 2.2.03-Polynomial-Features (also uses powers ), and 4.1.02-Decision-Trees (which don't need any of this — a good contrast to keep in mind).


Equipment checklist

Say the answer out loud before revealing.

What does the prime mark in mean on this page?
"The transformed version of " — not multiplication, not a derivative.
What is skew, in one phrase?
A lopsided data pile with a long thin tail on one side.
What does the dial control in ?
The strength of the power/squeeze; is no change, is , is .
What are and in ?
is the input (growth-steps), is the height the curve returns (the observed value).
What real-world process produces right-skewed data?
Multiplicative / constant-percent growth, shaped like .
What question does answer, and what is its default base here?
"What power gives me ?" — it undoes ; un-subscripted means natural log (base ).
Turn " of a ratio" into "s of the parts".
— multiplication becomes subtraction.
Why does become at ?
Write ; near zero , so the recipe cancels to .
What does homoscedasticity mean and why care?
Equal spread everywhere; linear regression assumes it, transforms restore it.
Which transforms fail on zero or negative data, and which one rescues them?
and Box-Cox need ; Yeo-Johnson handles zeros and negatives via mirrored cases.