Reduce feature skewness
Regression or classification features have strongly skewed distributions.
Scikit-Learn · Class
PowerTransformer applies a feature-wise Box-Cox or Yeo-Johnson transformation to make data more Gaussian-like. It estimates each feature's power parameter by maximum likelihood and standardizes the result by default.
PowerTransformer applies a monotonic Box-Cox or Yeo-Johnson transformation independently to each feature. It estimates each feature's parameter by maximum likelihood and, by default, standardizes the transformed columns to zero mean and unit variance.
class sklearn.preprocessing.PowerTransformer(*, method='yeo-johnson', standardize=True, copy=True)| Name | Type | Description |
|---|---|---|
method | {'yeo-johnson', 'box-cox'}, default='yeo-johnson' | Power transform method: 'yeo-johnson' or 'box-cox'. |
standardize | bool, default=True | Whether to apply zero-mean, unit-variance normalization after transforming. |
copy | bool, default=True | Whether to copy input data rather than attempt in-place computation during transformation. |
A fitted PowerTransformer instance from fit; transformed feature data from transform or fit_transform.
from sklearn.preprocessing import PowerTransformer
X = [[1.0, 2.0], [3.0, 2.0], [4.0, 5.0]]
transformer = PowerTransformer(method="yeo-johnson")
X_transformed = transformer.fit_transform(X)
print(X_transformed)
print(transformer.lambdas_)Fits one maximum-likelihood power parameter per feature, then transforms the data and applies the default standardization.
Regression or classification features have strongly skewed distributions.
Feature variance changes substantially across the range of observations.
A feature matrix includes zero or negative measurements.
A strictly positive matrix benefits from a power-family transformation.
It transforms each feature with a monotonic power transformation and estimates that feature's lambda independently by maximum likelihood. The goal is to make the feature more Gaussian-like while stabilizing variance and reducing skewness.
Follow-up: Which method handles negative values? Yeo-Johnson does; Box-Cox requires every input value to be strictly positive.
The default method is Yeo-Johnson, which supports positive and negative values. Box-Cox is the alternative and is restricted to strictly positive data.
Follow-up: What additional default behavior occurs after the nonlinear transform? The output is standardized to zero mean and unit variance.
Its default standardize=True applies zero-mean, unit-variance normalization to the transformed output. Set standardize=False when that scaling should not be performed.
Follow-up: How can the fitted transformation be reused on new data? Call transform on new samples after fitting, or use fit_transform for the training data.
sklearn.preprocessing.power_transformsklearn.preprocessing.QuantileTransformersklearn.preprocessing.FunctionTransformer