Python中有没有什么包可以进行数据转换:缩放、居中和Box-Cox转换,以消除数据的不对称性?在R中,这可以使用caret包来完成:
set.seed(1)
predictors = data.frame(x1 = rnorm(1000,
mean = 5,
sd = 2),
x2 = rexp(1000,
rate=10))
require(caret)
trans = preProcess(predictors,
c("BoxCox", "center", "scale"))
predictorsTrans = data.frame(
trans = predict(trans, predictors))我知道sklearn,但是我找不到上面提到的处理函数。
发布于 2015-12-21 14:05:20
对于缩放和居中,您可以使用sklearn中的preprocessing
from sklearn import preprocessing
centered_scaled_data = preprocessing.scale(original_data)对于Box-Cox,您可以使用来自scipy的boxcox
from scipy.stats import boxcox
boxcox_transformed_data = boxcox(original_data)对于偏斜度的计算,可以使用scipy中的skew
from scipy.stats import skew
skness = skew(original_data)您可以阅读有关Resolving Skewness in this post的更多详细信息。此外,您还可以找到有关Centering & Scaling here的更多详细信息。
发布于 2018-10-08 22:51:09
现在,学习有了一种方法来做你想做的事情。这提供了一个熟悉的API,并且很容易放入管道中。
sklearn版本0.20.0具有可通过power_transform方法使用的盒-Cox转换。该方法应用Box-Cox,然后对数据应用零均值、单位方差归一化。可以使用(standardize=False)编辑默认规格化。
sklearn.preprocessing.power_transform(X, method=’box-cox’, standardize=True, copy=True)在特征方面应用了幂变换,使数据更像高斯。
幂变换是一族参数单调变换,用于使数据更像高斯。这对于与异方差(非恒定方差)相关的建模问题或需要正态性的其他情况很有用。
目前,power_transform()支持Box-Cox变换。Box-Cox要求输入数据严格为正。通过最大似然法估计稳定方差和最小化偏度的最优参数。
默认情况下,对转换后的数据应用零均值、单位方差归一化。
http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.power_transform.html
主要文档页面没有提到这一点,但power_transform也支持Yeo-Johnson转换。
文档在这里也有一个很好的解释:http://scikit-learn.org/stable/modules/preprocessing.html#preprocessing-transformer
https://stackoverflow.com/questions/33944129
复制相似问题