Reverse Box-Cox transformation

前端 未结 4 925
自闭症患者
自闭症患者 2021-02-05 05:25

I am using SciPy\'s boxcox function to perform a Box-Cox transformation on a continuous variable.

from scipy.stats import boxcox
import numpy as np
y = np.random         


        
4条回答
  •  半阙折子戏
    2021-02-05 05:58

    In order to inverse the boxcox transformation from scipy.stats.boxcox using scipy.special.inv_boxcox you have to identify the lambda which was generated.

    First apply the transformation and print the lambda (ie. param).

    df[feature_boxcox], param = stats.boxcox(df[feature])
    print('Optimal lambda', param)
    

    Then in order to inverse the transformation you input the generated lambda.

    inv_boxcox(df[feature_boxcox], param)
    

提交回复
热议问题