How to apply Box-Cox transformation in Python?

Tom Kurushingal picture Tom Kurushingal · May 3, 2015 · Viewed 26.1k times · Source

I have data of the form:

X   Y
3.53    0
4.93    50
5.53    60
6.21    70
7.37    80
9.98    90
16.56   100

And I want to find out n so that this can be fit to a function of the form:

enter image description here

I am trying to determine n by Box-Cox transformation. How can this be done in Python?

Answer

blueogive picture blueogive · May 3, 2015

I think you want scipy.stats.boxcox.

from scipy import stats
import numpy as np

data = np.fromstring('3.53    0 4.93    50 5.53    60 6.21    70 7.37    80 9.98    90 16.56   100', sep=' ').reshape(7, 2)

stats.boxcox(data[0,])
(array([ 0.91024309,  1.06300488,  1.10938333,  1.15334193,  1.213348  ,
     1.30668122,  1.43178909]), -0.54874593147877893)