mojolearn.PowerTransformer#

class mojolearn.PowerTransformer(method='yeo-johnson', *, standardize=True, copy=True)[source]#

Bases: _PrepBase

Apply a power transform per feature to make the data more Gaussian.

Follows scikit-learn’s PowerTransformer. Each column gets the Yeo-Johnson or Box-Cox transform with the lambda that maximizes the log-likelihood, then (by default) is standardized to zero mean and unit variance. Lambda is searched in [-8, 8], so fitted lambdas can differ slightly from scikit-learn’s. NaN values are ignored in fit and kept as NaN. Input and output are float32.

Parameters:
  • method ({‘yeo-johnson’, ‘box-cox’}, default ‘yeo-johnson’) – 'box-cox' requires strictly positive data (ValueError otherwise).

  • standardize (bool, default True) – Standardize the transformed columns.

  • copy (bool, default True) – Accepted for scikit-learn compatibility; transform always returns a new array.

Variables:
  • lambdas_ (array of shape (n_features,)) – Fitted lambda of each column.

  • n_features_in_ (int) – Number of columns seen in fit.

  • numeric_mode_ (str) – Numeric mode the estimator was fitted in; transform runs in the same mode.

Notes

inverse_transform undoes the standardization, then the power transform.

Examples

>>> import numpy as np, mojolearn
>>> X = np.random.default_rng(0).lognormal(size=(1000, 4)).astype(np.float32)
>>> Xt = mojolearn.PowerTransformer().fit_transform(X)
__init__(method='yeo-johnson', *, standardize=True, copy=True)[source]#

Methods

fit(X[, y])

fit_transform(X[, y])

Fit to X, then transform X.

get_params([deep])

Return the constructor parameters as a dict.

inverse_transform(X)

set_params(**params)

Set constructor parameters.

transform(X)