# PowerTransformer

### *class* cuml.preprocessing.PowerTransformer(\*args, \*\*kwargs)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L2855)

Apply a power transform featurewise to make data more Gaussian-like.

Power transforms are a family of parametric, monotonic transformations
that are applied to make data more Gaussian-like. This is useful for
modeling issues related to heteroscedasticity (non-constant variance),
or other situations where normality is desired.

Currently, PowerTransformer supports the Box-Cox transform and the
Yeo-Johnson transform. The optimal parameter for stabilizing variance and
minimizing skewness is estimated through maximum likelihood.

Box-Cox requires input data to be strictly positive, while Yeo-Johnson
supports both positive or negative data.

By default, zero-mean, unit-variance normalization is applied to the
transformed data.

* **Parameters:**
  **method**
  : The power transform method. Available methods are:
    - ‘yeo-johnson’ [[1]](#r489b64a2def7-1), works with positive and negative values
    - ‘box-cox’ [[2]](#r489b64a2def7-2), only works with strictly positive values

  **standardize**
  : Set to True to apply zero-mean, unit-variance normalization to the
    transformed output.

  **copy**
  : Set to False to perform inplace computation during transformation.
* **Attributes:**
  **lambdas_**
  : The parameters of the power transformation for the selected features.

### Methods

| [`fit`](#cuml.preprocessing.PowerTransformer.fit)(X[, y])           | Estimate the optimal parameter lambda for each feature.             |
|------------------------------------------------------------------------|---------------------------------------------------------------------|
| [`fit_transform`](#cuml.preprocessing.PowerTransformer.fit_transform)(X[, y]) | Fit to data, then transform it.                                     |
| [`inverse_transform`](#cuml.preprocessing.PowerTransformer.inverse_transform)(X)  | Apply the inverse power transformation using the fitted lambdas.    |
| [`transform`](#cuml.preprocessing.PowerTransformer.transform)(X)          | Apply the power transform to each feature using the fitted lambdas. |

#### SEE ALSO
`power_transform`
: Equivalent function without the estimator API.

[`QuantileTransformer`](../cuml.preprocessing.QuantileTransformer/index.html.md#cuml.preprocessing.QuantileTransformer)
: Maps data to a standard normal distribution with the parameter `output_distribution='normal'`.

### Notes

NaNs are treated as missing values: disregarded in `fit`, and maintained
in `transform`.

### References

### Examples

```pycon
>>> import cupy as cp
>>> from cuml.preprocessing import PowerTransformer
>>> pt = PowerTransformer()
>>> data = cp.array([[1, 2], [3, 2], [4, 5]])
>>> print(pt.fit(data))
PowerTransformer()
>>> print(pt.lambdas_)
[ 1.386... -3.100...]
>>> print(pt.transform(data))
[[-1.316... -0.707...]
 [ 0.209... -0.707...]
 [ 1.106...  1.414...]]
```

<!-- !! processed by numpydoc !! -->

#### fit(X, y=None) → [PowerTransformer](#cuml.preprocessing.PowerTransformer)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L2949)

Estimate the optimal parameter lambda for each feature.

The optimal lambda parameter for minimizing skewness is estimated on
each feature independently using maximum likelihood.

* **Parameters:**
  **X**
  : The data used to estimate the optimal transformation parameters.

  **y**
* **Returns:**
  **self**

<!-- !! processed by numpydoc !! -->

#### fit_transform(X, y=None)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L2970)

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params
and returns a transformed version of X.

* **Parameters:**
  **X**

  **y**
  : Target values.

  **\*\*fit_params**
  : Additional fit parameters.
* **Returns:**
  **X_new**
  : Transformed array.

<!-- !! processed by numpydoc !! -->

#### get_feature_names_out(input_features=None)

Get output feature names for transformation.

* **Parameters:**
  **input_features**
  : Input features.
    - If `input_features` is [`None`](https://docs.python.org/3/builtins/constants.html#None), then `feature_names_in_` is
      used as feature names in. If `feature_names_in_` is not defined,
      then the following input feature names are generated:
      `["x0", "x1", ..., "x(n_features_in_ - 1)"]`.
    - If `input_features` is an array-like, then `input_features` must
      match `feature_names_in_` if `feature_names_in_` is defined.
* **Returns:**
  **feature_names_out**
  : Same as input features.

<!-- !! processed by numpydoc !! -->

#### get_params(deep=True)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L191)

Returns a dict of all params owned by this class. If the child class
has appropriately overridden the `_get_param_names` method and does not
need anything other than what is there in this method, then it doesn’t
have to override this method

<!-- !! processed by numpydoc !! -->

#### inverse_transform(X)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L3048)

Apply the inverse power transformation using the fitted lambdas.

The inverse of the Box-Cox transformation is given by:

```default
if lambda_ == 0:
    X = exp(X_trans)
else:
    X = (X_trans * lambda_ + 1) ** (1 / lambda_)
```

The inverse of the Yeo-Johnson transformation is given by:

```default
if X >= 0 and lambda_ == 0:
    X = exp(X_trans) - 1
elif X >= 0 and lambda_ != 0:
    X = (X_trans * lambda_ + 1) ** (1 / lambda_) - 1
elif X < 0 and lambda_ != 2:
    X = 1 - (-(2 - lambda_) * X_trans + 1) ** (1 / (2 - lambda_))
elif X < 0 and lambda_ == 2:
    X = 1 - exp(-X_trans)
```

* **Parameters:**
  **X**
  : The transformed data.
* **Returns:**
  **X**
  : The original data

<!-- !! processed by numpydoc !! -->

#### set_params(\*\*params)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L200)

Accepts a dict of params and updates the corresponding ones owned by
this class. If the child class has appropriately overridden the
`_get_param_names` method and does not need anything other than what is,
there in this method, then it doesn’t have to override this method

<!-- !! processed by numpydoc !! -->

#### transform(X)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L3013)

Apply the power transform to each feature using the fitted lambdas.

* **Parameters:**
  **X**
  : The data to be transformed using a power transformation.
* **Returns:**
  **X_trans**
  : The transformed data.

<!-- !! processed by numpydoc !! -->
