PowerTransformer
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.
For an example visualization, refer to Compare PowerTransformer with other scalers. To see the effect of Box-Cox and Yeo-Johnson transformations on different distributions, see: Map data to a normal distribution.
Read more in the User Guide.
Python Reference (opens in a new tab)
Constructors
constructor()
Signature
new PowerTransformer(opts?: object): PowerTransformer;
Parameters
Name | Type | Description |
---|---|---|
opts? | object | - |
opts.copy? | boolean | Set to false to perform inplace computation during transformation. Default Value true |
opts.method? | "yeo-johnson" | "box-cox" | The power transform method. Available methods are: Default Value 'yeo-johnson' |
opts.standardize? | boolean | Set to true to apply zero-mean, unit-variance normalization to the transformed output. Default Value true |
Returns
Defined in: generated/preprocessing/PowerTransformer.ts:33 (opens in a new tab)
Methods
dispose()
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Signature
dispose(): Promise<void>;
Returns
Promise
<void
>
Defined in: generated/preprocessing/PowerTransformer.ts:116 (opens in a new tab)
fit()
Estimate the optimal parameter lambda for each feature.
The optimal lambda parameter for minimizing skewness is estimated on each feature independently using maximum likelihood.
Signature
fit(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | The data used to estimate the optimal transformation parameters. |
opts.y? | any | Ignored. |
Returns
Promise
<any
>
Defined in: generated/preprocessing/PowerTransformer.ts:135 (opens in a new tab)
fit_transform()
Fit PowerTransformer
to X
, then transform X
.
Signature
fit_transform(opts: object): Promise<ArrayLike[]>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | The data used to estimate the optimal transformation parameters and to be transformed using a power transformation. |
opts.y? | any | Not used, present for API consistency by convention. |
Returns
Promise
<ArrayLike
[]>
Defined in: generated/preprocessing/PowerTransformer.ts:175 (opens in a new tab)
get_feature_names_out()
Get output feature names for transformation.
Signature
get_feature_names_out(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.input_features? | any | Input features. |
Returns
Promise
<any
>
Defined in: generated/preprocessing/PowerTransformer.ts:217 (opens in a new tab)
get_metadata_routing()
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Signature
get_metadata_routing(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.routing? | any | A MetadataRequest encapsulating routing information. |
Returns
Promise
<any
>
Defined in: generated/preprocessing/PowerTransformer.ts:257 (opens in a new tab)
init()
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Signature
init(py: PythonBridge): Promise<void>;
Parameters
Name | Type |
---|---|
py | PythonBridge |
Returns
Promise
<void
>
Defined in: generated/preprocessing/PowerTransformer.ts:72 (opens in a new tab)
inverse_transform()
Apply the inverse power transformation using the fitted lambdas.
The inverse of the Box-Cox transformation is given by:
Signature
inverse_transform(opts: object): Promise<ArrayLike[]>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | The transformed data. |
Returns
Promise
<ArrayLike
[]>
Defined in: generated/preprocessing/PowerTransformer.ts:296 (opens in a new tab)
set_output()
Set output container.
See Introducing the set_output API for an example on how to use the API.
Signature
set_output(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.transform? | "default" | "pandas" | Configure output of transform and fit\_transform . |
Returns
Promise
<any
>
Defined in: generated/preprocessing/PowerTransformer.ts:335 (opens in a new tab)
transform()
Apply the power transform to each feature using the fitted lambdas.
Signature
transform(opts: object): Promise<ArrayLike[]>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | The data to be transformed using a power transformation. |
Returns
Promise
<ArrayLike
[]>
Defined in: generated/preprocessing/PowerTransformer.ts:370 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/preprocessing/PowerTransformer.ts:31 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/preprocessing/PowerTransformer.ts:30 (opens in a new tab)
_py
PythonBridge
Defined in: generated/preprocessing/PowerTransformer.ts:29 (opens in a new tab)
id
string
Defined in: generated/preprocessing/PowerTransformer.ts:26 (opens in a new tab)
opts
any
Defined in: generated/preprocessing/PowerTransformer.ts:27 (opens in a new tab)
Accessors
feature_names_in_
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Signature
feature_names_in_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/preprocessing/PowerTransformer.ts:459 (opens in a new tab)
lambdas_
The parameters of the power transformation for the selected features.
Signature
lambdas_(): Promise<any[]>;
Returns
Promise
<any
[]>
Defined in: generated/preprocessing/PowerTransformer.ts:405 (opens in a new tab)
n_features_in_
Number of features seen during fit.
Signature
n_features_in_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/preprocessing/PowerTransformer.ts:432 (opens in a new tab)
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/preprocessing/PowerTransformer.ts:59 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/preprocessing/PowerTransformer.ts:63 (opens in a new tab)