Validate the input before fit and transform. Parameters ---------- X : array-like of shape (n_samples, n_features) in_fit : bool Whether or not `_check_input` is called from `fit` or other methods, e.g. `predict`, `transform`, etc. c
(self, X, in_fit, check_positive=False, check_shape=False)
| 3600 | return lmbda |
| 3601 | |
| 3602 | def _check_input(self, X, in_fit, check_positive=False, check_shape=False): |
| 3603 | """Validate the input before fit and transform. |
| 3604 | |
| 3605 | Parameters |
| 3606 | ---------- |
| 3607 | X : array-like of shape (n_samples, n_features) |
| 3608 | |
| 3609 | in_fit : bool |
| 3610 | Whether or not `_check_input` is called from `fit` or other |
| 3611 | methods, e.g. `predict`, `transform`, etc. |
| 3612 | |
| 3613 | check_positive : bool, default=False |
| 3614 | If True, check that all data is positive and non-zero (only if |
| 3615 | ``self.method=='box-cox'``). |
| 3616 | |
| 3617 | check_shape : bool, default=False |
| 3618 | If True, check that n_features matches the length of self.lambdas_ |
| 3619 | """ |
| 3620 | X = validate_data( |
| 3621 | self, |
| 3622 | X, |
| 3623 | ensure_2d=True, |
| 3624 | dtype=FLOAT_DTYPES, |
| 3625 | force_writeable=True, |
| 3626 | copy=self.copy, |
| 3627 | ensure_all_finite="allow-nan", |
| 3628 | reset=in_fit, |
| 3629 | ) |
| 3630 | |
| 3631 | with warnings.catch_warnings(): |
| 3632 | warnings.filterwarnings("ignore", r"All-NaN (slice|axis) encountered") |
| 3633 | if check_positive and self.method == "box-cox" and np.nanmin(X) <= 0: |
| 3634 | raise ValueError( |
| 3635 | "The Box-Cox transformation can only be " |
| 3636 | "applied to strictly positive data" |
| 3637 | ) |
| 3638 | |
| 3639 | if check_shape and not X.shape[1] == len(self.lambdas_): |
| 3640 | raise ValueError( |
| 3641 | "Input data has a different number of features " |
| 3642 | "than fitting data. Should have {n}, data has {m}".format( |
| 3643 | n=len(self.lambdas_), m=X.shape[1] |
| 3644 | ) |
| 3645 | ) |
| 3646 | |
| 3647 | return X |
| 3648 | |
| 3649 | def __sklearn_tags__(self): |
| 3650 | tags = super().__sklearn_tags__() |
no test coverage detected