How to use the imblearn.utils.check_neighbors_object function in imblearn

To help you get started, we’ve selected a few imblearn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scikit-learn-contrib / imbalanced-learn / imblearn / under_sampling / _prototype_selection / _edited_nearest_neighbours.py View on Github external
def _validate_estimator(self):
        """Private function to create the NN estimator"""
        if self.max_iter < 2:
            raise ValueError(
                "max_iter must be greater than 1."
                " Got {} instead.".format(type(self.max_iter))
            )

        self.nn_ = check_neighbors_object(
            "n_neighbors", self.n_neighbors, additional_neighbor=1
        )

        self.enn_ = EditedNearestNeighbours(
            sampling_strategy=self.sampling_strategy,
            n_neighbors=self.nn_,
            kind_sel=self.kind_sel,
            n_jobs=self.n_jobs,
        )
github scikit-learn-contrib / imbalanced-learn / imblearn / under_sampling / _prototype_selection / _nearmiss.py View on Github external
def _validate_estimator(self):
        """Private function to create the NN estimator"""

        self.nn_ = check_neighbors_object("n_neighbors", self.n_neighbors)
        self.nn_.set_params(**{"n_jobs": self.n_jobs})

        if self.version == 3:
            self.nn_ver3_ = check_neighbors_object(
                "n_neighbors_ver3", self.n_neighbors_ver3
            )
            self.nn_ver3_.set_params(**{"n_jobs": self.n_jobs})

        if self.version not in (1, 2, 3):
            raise ValueError(
                "Parameter `version` must be 1, 2 or 3, got"
                " {}".format(self.version)
            )
github AlgoWit / geometric-smote / gsmote / geometric_smote.py View on Github external
# Check random state
        self.random_state_ = check_random_state(self.random_state)

        # Validate strategy
        if self.selection_strategy not in SELECTION_STRATEGY:
            error_msg = (
                'Unknown selection_strategy for Geometric SMOTE algorithm. '
                'Choices are {}. Got {} instead.'
            )
            raise ValueError(
                error_msg.format(SELECTION_STRATEGY, self.selection_strategy)
            )

        # Create nearest neighbors object for positive class
        if self.selection_strategy in ('minority', 'combined'):
            self.nns_pos_ = check_neighbors_object(
                'nns_positive', self.k_neighbors, additional_neighbor=1
            )
            self.nns_pos_.set_params(n_jobs=self.n_jobs)

        # Create nearest neighbors object for negative class
        if self.selection_strategy in ('majority', 'combined'):
            self.nn_neg_ = check_neighbors_object('nn_negative', nn_object=1)
            self.nn_neg_.set_params(n_jobs=self.n_jobs)
github scikit-learn-contrib / imbalanced-learn / imblearn / over_sampling / _smote.py View on Github external
def _validate_estimator(self):
        """Check the NN estimators shared across the different SMOTE
        algorithms.
        """
        self.nn_k_ = check_neighbors_object(
            "k_neighbors", self.k_neighbors, additional_neighbor=1
        )
        self.nn_k_.set_params(**{"n_jobs": self.n_jobs})
github scikit-learn-contrib / imbalanced-learn / imblearn / under_sampling / _prototype_selection / _nearmiss.py View on Github external
def _validate_estimator(self):
        """Private function to create the NN estimator"""

        self.nn_ = check_neighbors_object("n_neighbors", self.n_neighbors)
        self.nn_.set_params(**{"n_jobs": self.n_jobs})

        if self.version == 3:
            self.nn_ver3_ = check_neighbors_object(
                "n_neighbors_ver3", self.n_neighbors_ver3
            )
            self.nn_ver3_.set_params(**{"n_jobs": self.n_jobs})

        if self.version not in (1, 2, 3):
            raise ValueError(
                "Parameter `version` must be 1, 2 or 3, got"
                " {}".format(self.version)
            )
github scikit-learn-contrib / imbalanced-learn / imblearn / over_sampling / _adasyn.py View on Github external
def _validate_estimator(self):
        """Create the necessary objects for ADASYN"""
        self.nn_ = check_neighbors_object(
            "n_neighbors", self.n_neighbors, additional_neighbor=1
        )
        self.nn_.set_params(**{"n_jobs": self.n_jobs})
github scikit-learn-contrib / imbalanced-learn / imblearn / under_sampling / _prototype_selection / _neighbourhood_cleaning_rule.py View on Github external
def _validate_estimator(self):
        """Create the objects required by NCR."""
        self.nn_ = check_neighbors_object(
            "n_neighbors", self.n_neighbors, additional_neighbor=1
        )
        self.nn_.set_params(**{"n_jobs": self.n_jobs})

        if self.kind_sel not in SEL_KIND:
            raise NotImplementedError

        if self.threshold_cleaning > 1 or self.threshold_cleaning < 0:
            raise ValueError(
                "'threshold_cleaning' is a value between 0 and 1."
                " Got {} instead.".format(self.threshold_cleaning)
            )
github scikit-learn-contrib / imbalanced-learn / imblearn / under_sampling / _prototype_selection / _edited_nearest_neighbours.py View on Github external
def _validate_estimator(self):
        """Validate the estimator created in the ENN."""
        self.nn_ = check_neighbors_object(
            "n_neighbors", self.n_neighbors, additional_neighbor=1
        )
        self.nn_.set_params(**{"n_jobs": self.n_jobs})

        if self.kind_sel not in SEL_KIND:
            raise NotImplementedError
github scikit-learn-contrib / imbalanced-learn / imblearn / under_sampling / _prototype_selection / _edited_nearest_neighbours.py View on Github external
def _validate_estimator(self):
        """Create objects required by AllKNN"""
        if self.kind_sel not in SEL_KIND:
            raise NotImplementedError

        self.nn_ = check_neighbors_object(
            "n_neighbors", self.n_neighbors, additional_neighbor=1
        )

        self.enn_ = EditedNearestNeighbours(
            sampling_strategy=self.sampling_strategy,
            n_neighbors=self.nn_,
            kind_sel=self.kind_sel,
            n_jobs=self.n_jobs,
        )