Performing Box-Cox transformations
The Box-Cox transformation is a generalization of the power family of transformations and is defined as follows:
Here, y is the variable and λ is the transformation parameter. It includes important special cases of transformations, such as untransformed (λ = 1), the logarithm (λ = 0), the reciprocal (λ = - 1), the square root (when λ = 0.5, it applies a scaled and shifted version of the square root function), and the cube root.
The Box-Cox transformation evaluates several values of λ using the maximum likelihood and selects the λ parameter that returns the best transformation.
In this recipe, we will perform the Box-Cox transformation using scikit-learn and Feature-engine.
Note
The Box-Cox transformation can only be used on positive variables. If your variables have negative values, try the Yeo-Johnson transformation, which is described in the next recipe, Performing Yeo-Johnson transformation...