def _fit_strategy_validator(self, X):
        """Internal helper method to validate strategies appropriate for fit.

        Checks whether strategies match with type of column they are applied
        to. If not, error is raised through `check_strategy_fit` method.
        """

        # remove nan columns and store colnames
        cols = X.columns.tolist()
        self._strats = check_strategy_fit(self.strategy, cols)

        # if predictors is a list...
        if isinstance(self.predictors, (tuple, list)):
            # and it is not the same list of predictors for every iteration...
            if not all([isinstance(x, str) for x in self.predictors]):
                len_pred = len(self.predictors)
                # raise error if not the correct length
                if len_pred != self.n:
                    err = f"Predictors has {len_pred} items. Need {self.n}"
                    raise ValueError(err)
                # check predictors for each in list
                self._preds = [
                    check_predictors_fit(p, cols)
                    for p in self.predictors
                ]
            # if it is a list, but not a list of objects...
            else:
                # broadcast predictors
                self._preds = check_predictors_fit(self.predictors, cols)
                self._preds = [self._preds]*self.n
        # if string or dictionary...
        else:
            # broadcast predictors
            self._preds = check_predictors_fit(self.predictors, cols)
            self._preds = [self._preds]*self.n
Esempio n. 2
0
    def _fit_strategy_validator(self, X):
        """Private method to validate strategies appropriate for fit.

        Checks whether strategies match with type of column they are applied
        to. If not, error is raised through `check_strategy_fit` method.
        """

        # remove nan columns and store colnames
        cols = X.columns.tolist()
        self._strats = check_strategy_fit(self.strategy, cols)
        self._preds = check_predictors_fit(self.predictors, cols)
Esempio n. 3
0
    def _fit_strategy_validator(self, X):
        """Internal helper method to validate behavior appropriate for fit."""

        # remove nan columns and store colnames
        cols = X.columns.tolist()
        self._preds = check_predictors_fit(self.predictors, cols)

        # next, prep the categorical / numerical split
        # only necessary for classes that use other features
        # wont see this requirement in the single imputer
        self.data_mi = X.isnull().astype(int)