如何在 Python 中应用 Box-Cox 变换?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30018875/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to apply Box-Cox transformation in Python?
提问by Tom Kurushingal
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:
我想找出 n 以便它适合以下形式的函数:
I am trying to determine n by Box-Cox transformation. How can this be done in Python?
我试图通过 Box-Cox 变换来确定 n。这如何在 Python 中完成?
回答by blueogive
I think you want scipy.stats.boxcox.
我想你想要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)
回答by 1dhiman
回答by yogesh agrawal
For Box-Cox Transformation in Python you must follow below steps:-
对于 Python 中的 Box-Cox 转换,您必须遵循以下步骤:-
from scipy.stats import boxcox
from scipy.special import inv_boxcox
y =[10,20,30,40,50]
y,fitted_lambda= boxcox(y,lmbda=None)
inv_boxcox(y,fitted_lambda)
in scipy.special
package box-cox
method is present but that expect lambda
explicitly.Hence i used box-cox from scipy.stats
and inv_box-cox from special as inv_boxcox not available in scipy.stats.
inscipy.special
包box-cox
方法存在,但lambda
明确期望。因此,我使用了 box-cox fromscipy.stats
和 inv_box-cox from special 因为 inv_boxcox 在 scipy.stats 中不可用。