Class: 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.
Constructors
new PowerTransformer()
new PowerTransformer(
opts
?):PowerTransformer
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.copy ? | boolean | Set to false to perform inplace computation during transformation. |
opts.method ? | "yeo-johnson" | "box-cox" | The power transform method. Available methods are: |
opts.standardize ? | boolean | Set to true to apply zero-mean, unit-variance normalization to the transformed output. |
Returns PowerTransformer
Defined in generated/preprocessing/PowerTransformer.ts:33
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/preprocessing/PowerTransformer.ts:31 |
_isInitialized | boolean | false | generated/preprocessing/PowerTransformer.ts:30 |
_py | PythonBridge | undefined | generated/preprocessing/PowerTransformer.ts:29 |
id | string | undefined | generated/preprocessing/PowerTransformer.ts:26 |
opts | any | undefined | generated/preprocessing/PowerTransformer.ts:27 |
Accessors
feature_names_in_
Get Signature
get feature_names_in_():
Promise
<ArrayLike
>
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Returns Promise
<ArrayLike
>
Defined in generated/preprocessing/PowerTransformer.ts:448
lambdas_
Get Signature
get lambdas_():
Promise
<any
[]>
The parameters of the power transformation for the selected features.
Returns Promise
<any
[]>
Defined in generated/preprocessing/PowerTransformer.ts:394
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
Number of features seen during fit.
Returns Promise
<number
>
Defined in generated/preprocessing/PowerTransformer.ts:421
py
Get Signature
get py():
PythonBridge
Returns PythonBridge
Set Signature
set py(
pythonBridge
):void
Parameters
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
Returns void
Defined in generated/preprocessing/PowerTransformer.ts:59
Methods
dispose()
dispose():
Promise
<void
>
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Returns Promise
<void
>
Defined in generated/preprocessing/PowerTransformer.ts:113
fit()
fit(
opts
):Promise
<any
>
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
Parameter | 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:132
fit_transform()
fit_transform(
opts
):Promise
<ArrayLike
[]>
Fit PowerTransformer
to X
, then transform X
.
Parameters
Parameter | 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:171
get_feature_names_out()
get_feature_names_out(
opts
):Promise
<any
>
Get output feature names for transformation.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.input_features ? | any | Input features. |
Returns Promise
<any
>
Defined in generated/preprocessing/PowerTransformer.ts:212
get_metadata_routing()
get_metadata_routing(
opts
):Promise
<any
>
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.routing ? | any | A MetadataRequest encapsulating routing information. |
Returns Promise
<any
>
Defined in generated/preprocessing/PowerTransformer.ts:250
init()
init(
py
):Promise
<void
>
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Parameters
Parameter | Type |
---|---|
py | PythonBridge |
Returns Promise
<void
>
Defined in generated/preprocessing/PowerTransformer.ts:72
inverse_transform()
inverse_transform(
opts
):Promise
<ArrayLike
[]>
Apply the inverse power transformation using the fitted lambdas.
The inverse of the Box-Cox transformation is given by:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | The transformed data. |
Returns Promise
<ArrayLike
[]>
Defined in generated/preprocessing/PowerTransformer.ts:288
set_output()
set_output(
opts
):Promise
<any
>
Set output container.
See Introducing the set_output API for an example on how to use the API.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.transform ? | "default" | "pandas" | "polars" | Configure output of transform and fit_transform . |
Returns Promise
<any
>
Defined in generated/preprocessing/PowerTransformer.ts:326
transform()
transform(
opts
):Promise
<ArrayLike
[]>
Apply the power transform to each feature using the fitted lambdas.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | The data to be transformed using a power transformation. |
Returns Promise
<ArrayLike
[]>