如何在Python中应用Box-Cox变换?

2024-06-06 08:02:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我有表格资料:

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

我想找出n,这样它就可以符合形式的函数:

enter image description here

我试图通过Box-Cox变换来确定n。在Python中如何实现这一点?


Tags: 函数box形式表格资料cox
2条回答

我想你想要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)

1+x的Box-Cox可能有助于零(boxcox1p

from scipy.special import boxcox1p
boxcox1p([0.01, 0.1], 0.25)

相关问题 更多 >