Apply the power transform to each feature using the fitted lambdas. Parameters ---------- X : array-like of shape (n_samples, n_features) The data to be transformed using a power transformation. Returns ------- X_trans : ndarray of shape
(self, X)
| 3451 | return X |
| 3452 | |
| 3453 | def transform(self, X): |
| 3454 | """Apply the power transform to each feature using the fitted lambdas. |
| 3455 | |
| 3456 | Parameters |
| 3457 | ---------- |
| 3458 | X : array-like of shape (n_samples, n_features) |
| 3459 | The data to be transformed using a power transformation. |
| 3460 | |
| 3461 | Returns |
| 3462 | ------- |
| 3463 | X_trans : ndarray of shape (n_samples, n_features) |
| 3464 | The transformed data. |
| 3465 | """ |
| 3466 | check_is_fitted(self) |
| 3467 | X = self._check_input(X, in_fit=False, check_positive=True, check_shape=True) |
| 3468 | |
| 3469 | transform_function = { |
| 3470 | "box-cox": boxcox, |
| 3471 | "yeo-johnson": stats.yeojohnson, |
| 3472 | }[self.method] |
| 3473 | for i, lmbda in enumerate(self.lambdas_): |
| 3474 | with np.errstate(invalid="ignore"): # hide NaN warnings |
| 3475 | X[:, i] = transform_function(X[:, i], lmbda) |
| 3476 | |
| 3477 | if self.standardize: |
| 3478 | X = self._scaler.transform(X) |
| 3479 | |
| 3480 | return X |
| 3481 | |
| 3482 | def inverse_transform(self, X): |
| 3483 | """Apply the inverse power transformation using the fitted lambdas. |