逆 Box-Cox 变换 [英] Reverse Box-Cox transformation

查看:94
本文介绍了逆 Box-Cox 变换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SciPy 的 boxcox 函数 对连续变量执行 Box-Cox 变换.

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.random(100)
y_box, lambda_ = ss.boxcox(y + 1) # Add 1 to be able to transform 0 values

然后,我拟合了一个统计模型来预测这个 Box-Cox 转换变量的值.模型预测采用 Box-Cox 尺度,我想将它们转换为变量的原始尺度.

Then, I fit a statistical model to predict the values of this Box-Cox transformed variable. The model predictions are in the Box-Cox scale and I want to transform them to the original scale of the variable.

from sklearn.ensemble import RandomForestRegressor
rf = RandomForestRegressor()
X = np.random.random((100, 100))
rf.fit(X, y_box)
pred_box = rf.predict(X)

但是,我找不到在给定转换数据和 lambda 的情况下执行反向 Box-Cox 转换的 SciPy 函数.有这样的函数吗?我现在编写了一个逆变换.

However, I can't find a SciPy function that performs a reverse Box-Cox transformation given transformed data and lambda. Is there such a function? I coded an inverse transformation for now.

pred_y = np.power((y_box * lambda_) + 1, 1 / lambda_) - 1

推荐答案

感谢 @Warren Weckesser,我了解到 SciPy 的当前实现没有反转 Box-Cox 转换的功能.但是,未来的 SciPy 版本可能具有此功能.目前,我在问题中提供的代码可能会帮助其他人反转 Box-Cox 转换.

Thanks to @Warren Weckesser, I've learned that the current implementation of SciPy does not have a function to reverse a Box-Cox transformation. However, a future SciPy release may have this function. For now, the code I provide in my question may serve others to reverse Box-Cox transformations.

这篇关于逆 Box-Cox 变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆