Chip Foundry Services Request Assessment

Box Cox

Box-Cox Transformation is a power transformation that automatically finds the optimal mathematical function to normalize data — searching over a parameter $\lambda (\lambda)$ to determine whether the data needs a log transform $(\lambda =0)$, square root $(\lambda =0.5)$, reciprocal $(\lambda =-1)$, no transform $(\lambda =1)$, or any other power between them, making it the data-driven alternative to manually guessing which transformation to apply to skewed features.

What Is the Box-Cox Transformation?

  • Definition: A family of power transformations parameterized by $\lambda $ that transforms the data to be as close to a normal distribution as possible — the algorithm finds the optimal $\lambda $ using maximum likelihood estimation.
  • The Formula:
$$- If \lambda$$

eq 0: $y_{\text{new}} = \dfrac{y^{\lambda} - 1}{\lambda}$

$$- If \lambda = 0: y_{\text{new}} = \log(y)$$
  • Why Not Just Use Log?: Log transformation assumes the data needs logarithmic compression. But some data needs square root $(\lambda =0.5)$, cube root $(\lambda =0.33)$, or even no transformation $(\lambda =1). \text{Box-Cox}$ finds the optimal power automatically.

Lambda Values Explained

$\lambda $ (Lambda)TransformationWhen OptimalEffect
-1Reciprocal $(1/y)$Heavily right-skewedExtreme compression
-0.5Reciprocal square root $(1/\sqrt{y})$Very right-skewedStrong compression
0$Log(y)$Moderately right-skewedLogarithmic compression
0.5Square root $(\sqrt{y})$Mildly right-skewedMild compression
1No transformation ($y$ itself)Already normalNo change needed
2Square $(y^2)$Left-skewedExpansion (rare)

How $\text{Box-Cox} Finds Optimal \lambda $

StepProcess
1. Try many $\lambda $ valuesTest $\lambda $ from -5 to +5 in small increments
2. For each $\lambda $, transform dataApply $y^{\lambda}$ formula
3. Measure normalityLog-likelihood of the transformed data under a normal distribution
4. Select best $\lambda $The $\lambda $ that maximizes log-likelihood (makes data most normal)

Python Implementation

from scipy.stats import boxcox
from sklearn.preprocessing import PowerTransformer

# SciPy (returns transformed data + optimal lambda)
data_transformed, optimal_lambda = boxcox(data)
print(f"Optimal lambda: {optimal_lambda:.2f}")

# Scikit-learn (fits inside pipeline, handles inverse)
pt = PowerTransformer(method='box-cox')  # requires positive data
X_transformed = pt.fit_transform(X)

Box-Cox vs Yeo-Johnson

PropertyBox-CoxYeo-Johnson
Input requirementStrictly positive ($y >$ 0)Any value (positive, zero, negative)
Zero handlingCannot handle zerosYes
Negative valuesCannot handleYes
Optimal forPositive continuous dataGeneral-purpose
Scikit-learn`PowerTransformer(method='box-cox')``PowerTransformer(method='yeo-johnson')`

When to Use

Use Box-Cox / Yeo-JohnsonDon't Use
Linear models that assume normalityTree-based models (don't need normality)
Right or left-skewed featuresAlready normally distributed data
When you don't know which transform to applyWhen you know log transform is correct
Preprocessing for statistical testsCategorical or binary features

Box-Cox Transformation is the automated alternative to manual transformation selection — finding the optimal power parameter $\lambda $ through maximum likelihood estimation to produce the most normal-like distribution possible, with Yeo-Johnson as its generalization that handles the zero and negative values that Box-Cox cannot.