Reverse Box-Cox transformation

前端 未结 4 924
自闭症患者
自闭症患者 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 06:00

    1. Here it is the code. It is working and just test. Scipy used neperian logarithm, i check the BoxCox transformation paper and it seens that they used log10. I kept with neperian, because it works with scipy
    2. Follow the code:

      #Function
      def invboxcox(y,ld):
         if ld == 0:
            return(np.exp(y))
         else:
            return(np.exp(np.log(ld*y+1)/ld))
      
      # Test the code
      x=[100]
      ld = 0
      y = stats.boxcox(x,ld)
      print invboxcox(y[0],ld)
      

提交回复
热议问题