2.1.9 · D3Data Preprocessing & Feature Engineering

Worked examples — Log and power transformations

3,095 words14 min readBack to topic

The scenario matrix

Every case a log/power transform can throw at you falls into one of these cells. The columns are the input situation; the rows are which tool answers it.

Cell Input situation Right tool Worked in
A , big right skew Ex 1
B , contains a zero (log1p) Ex 2
C , mild skew (power ) Ex 3
D , unknown best shape Box-Cox, general Ex 4
E Limiting case Box-Cox collapses to Ex 5
F Data has negative values Yeo-Johnson, branch Ex 6
G Yeo-Johnson positive branch + the seam at Yeo-Johnson continuity Ex 7
H Real-world word problem: model trained on log target, must report dollars inverse transform + Jensen bias Ex 8
I Exam twist: proportion in , edge behaviour at and logit Ex 9

Two figures carry the geometry: Figure 1 shows how each power bends the number line (used in Cells C–E), and Figure 2 shows the logit stretching the interval to the whole line (used in Cell I).

Figure — Log and power transformations

Look at the curves above. The straight diagonal is (do nothing). As drops below 1, big inputs get pulled down more than small ones — that is exactly what "compress the right tail" means. When passes through the family becomes the log curve (dashed). Below (reciprocal) it flattens even harder.


Cell A — big positive right skew →


Cell B — a zero in the data →


Cell C — mild skew → square root


Cell D — unknown shape → Box-Cox with a general


Cell E — the limiting case


Cell F — negative input → Yeo-Johnson, branch


Cell G — Yeo-Johnson positive branch + the seam at zero


Cell H — real-world word problem: inverse transform a prediction


Cell I — exam twist: proportions with the logit


Recall Self-test

Why does adding 1 before a log fix a zero? ::: but , finite and clean. What single value of turns Box-Cox into , and why? ::: ; the limit resolves by L'Hôpital to , the only value keeping the curve continuous. Which Yeo-Johnson makes the negative-branch denominator zero, and how is it handled? ::: ; the hole is filled by L'Hôpital to give . When is Yeo-Johnson mandatory over Box-Cox? ::: When the data contains negative or zero values — Box-Cox needs . Why add when un-logging a prediction? ::: is convex, so (Jensen); corrects the resulting under-prediction. What do and map to under logit? ::: and respectively.

Connections