Performing Box-Cox transformation
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, including 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.
In the Box-Cox transformation, several values of λ are evaluated using the maximum likelihood, and the λ parameter that returns the best transformation is selected.
In this recipe, we will perform 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...