pyts.preprocessing.PowerTransformer

class pyts.preprocessing.PowerTransformer(method='yeo-johnson', standardize=True)[来源]

对样本进行幂变换,使数据更接近高斯分布。

幂变换是一系列参数化、单调的转换方法,用于使数据更接近高斯分布。这对于处理与异方差性(非常数方差)相关的建模问题非常有用,或在其他需要正态性的场景中也很有帮助。

目前,PowerTransformer支持Box-Cox变换和Yeo-Johnson变换。通过最大似然估计来估计稳定方差和最小化偏度的最佳参数。

Box-Cox变换要求输入数据必须严格为正数,而Yeo-Johnson变换同时支持正数和负数数据。

默认情况下,对转换后的数据应用零均值、单位方差的归一化处理。

参数:
method : ‘yeo-johnson’ or ‘box-cox’ (默认 = ‘yeo-johnson’)

幂变换方法。可选方法有:

  • ‘yeo-johnson’ [1],适用于正值和负值
  • ‘box-cox’ [2],仅适用于严格正值
standardize : boolean (默认 = True)

设置为True时,将对变换后的输出应用零均值、单位方差的归一化处理。

注意事项

NaN值被视为缺失值:在fit中被忽略,并在transform中保留。

参考文献

[1]I.K. Yeo 和 R.A. Johnson, "一种新的幂变换家族用于改进正态性或对称性。" Biometrika, 87(4), pp.954-959, (2000).
[2]G.E.P. Box 和 D.R. Cox,《转换分析》,英国皇家统计学会期刊B辑,26卷,211-252页(1964年)。

示例

>>> import numpy as np
>>> from pyts.preprocessing import PowerTransformer
>>> X = [[1, 3, 4], [2, 2, 5]]
>>> pt = PowerTransformer()
>>> print(pt.transform(X))
[[-1.316...  0.209...  1.106...]
 [-0.707... -0.707...  1.414...]]

方法

__init__([method, standardize]) Initialize self.
fit([X, y]) Pass.
fit_transform(X[, y]) Fit to data, then transform it.
get_params([deep]) Get parameters for this estimator.
set_params(**params) Set the parameters of this estimator.
transform(X) Transform the data.
__init__(method='yeo-johnson', standardize=True)[来源]

初始化自身。查看 help(type(self)) 获取准确的签名信息。

fit(X=None, y=None)[来源]

通过。

参数:
X

忽略

y

忽略

返回值:
self : object
fit_transform(X, y=None, **fit_params)

拟合数据,然后进行转换。

使用可选参数fit_params将转换器适配到Xy,并返回转换后的X版本。

参数:
X : array-like, shape = (n_samples, n_timestamps)

单变量时间序列。

y : None or array-like, shape = (n_samples,) (default = None)

目标值(无监督转换时为None)。

**fit_params : dict

额外的拟合参数。

返回值:
X_new : array

转换后的数组。

get_params(deep=True)

获取此估计器的参数。

参数:
deep : bool, default=True

如果为True,将返回此估计器及其包含的子估计器的参数。

返回值:
params : dict

参数名称映射到对应的值。

set_params(**params)

设置此估计器的参数。

该方法不仅适用于简单的估计器,也适用于嵌套对象(如Pipeline)。后者采用__形式的参数,从而可以更新嵌套对象的每个组件。

参数:
**params : dict

估计器参数。

返回值:
self : 估计器实例

估计器实例。

transform(X)[来源]

转换数据。

参数:
X : array-like, shape = (n_samples, n_timestamps)

待转换的数据。

返回值:
X_new : array-like, shape = (n_samples, n_timestamps)

转换后的数据。

使用 pyts.preprocessing.PowerTransformer 的示例

Transformers

Transformers

转换器