diff --git a/doc/ensemble.rst b/doc/ensemble.rst index 0700ea0aa..159a23b76 100644 --- a/doc/ensemble.rst +++ b/doc/ensemble.rst @@ -59,7 +59,7 @@ random under-sampler:: BalancedBaggingClassifier(...) >>> y_pred = bbc.predict(X_test) >>> balanced_accuracy_score(y_test, y_pred) # doctest: +ELLIPSIS - 0.80... + 0.8... .. _forest: diff --git a/examples/model_selection/plot_validation_curve.py b/examples/model_selection/plot_validation_curve.py index 7e6ffdb68..5d83e7497 100644 --- a/examples/model_selection/plot_validation_curve.py +++ b/examples/model_selection/plot_validation_curve.py @@ -39,7 +39,7 @@ param_range = range(1, 11) train_scores, test_scores = ms.validation_curve( pipeline, X, y, param_name="smote__k_neighbors", param_range=param_range, - cv=3, scoring=scorer, n_jobs=1) + cv=3, scoring=scorer) train_scores_mean = np.mean(train_scores, axis=1) train_scores_std = np.std(train_scores, axis=1) test_scores_mean = np.mean(test_scores, axis=1) diff --git a/imblearn/combine/_smote_enn.py b/imblearn/combine/_smote_enn.py index 10d423ddd..657e2a222 100644 --- a/imblearn/combine/_smote_enn.py +++ b/imblearn/combine/_smote_enn.py @@ -45,9 +45,12 @@ class SMOTEENN(BaseSampler): :class:`imblearn.under_sampling.EditedNearestNeighbours` object with sampling strategy='all' will be given. - n_jobs : int, optional (default=1) - The number of threads to open if possible. - Will not apply to smote and enn given by the user. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. Notes ----- @@ -93,7 +96,7 @@ def __init__( random_state=None, smote=None, enn=None, - n_jobs=1, + n_jobs=None, ): super().__init__() self.sampling_strategy = sampling_strategy diff --git a/imblearn/combine/_smote_tomek.py b/imblearn/combine/_smote_tomek.py index af99d002d..595b208be 100644 --- a/imblearn/combine/_smote_tomek.py +++ b/imblearn/combine/_smote_tomek.py @@ -45,9 +45,12 @@ class SMOTETomek(BaseSampler): given, a :class:`imblearn.under_sampling.TomekLinks` object with sampling strategy='all' will be given. - n_jobs : int, optional (default=1) - The number of threads to open if possible. - Will not apply to smote and tomek given by the user. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. Notes ----- @@ -93,7 +96,7 @@ def __init__( random_state=None, smote=None, tomek=None, - n_jobs=1, + n_jobs=None, ): super().__init__() self.sampling_strategy = sampling_strategy diff --git a/imblearn/ensemble/_bagging.py b/imblearn/ensemble/_bagging.py index e77ab892d..26bb2b4b1 100644 --- a/imblearn/ensemble/_bagging.py +++ b/imblearn/ensemble/_bagging.py @@ -73,9 +73,12 @@ class BalancedBaggingClassifier(BaggingClassifier): replacement : bool, optional (default=False) Whether or not to sample randomly with replacement or not. - n_jobs : int, optional (default=1) - The number of jobs to run in parallel for both `fit` and `predict`. - If -1, then the number of jobs is set to the number of cores. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. {random_state} @@ -178,7 +181,7 @@ def __init__( warm_start=False, sampling_strategy="auto", replacement=False, - n_jobs=1, + n_jobs=None, random_state=None, verbose=0, ): diff --git a/imblearn/ensemble/_easy_ensemble.py b/imblearn/ensemble/_easy_ensemble.py index 808d36b97..2c02d6c59 100644 --- a/imblearn/ensemble/_easy_ensemble.py +++ b/imblearn/ensemble/_easy_ensemble.py @@ -53,9 +53,12 @@ class EasyEnsembleClassifier(BaggingClassifier): replacement : bool, optional (default=False) Whether or not to sample randomly with replacement or not. - n_jobs : int, optional (default=1) - The number of jobs to run in parallel for both `fit` and `predict`. - If -1, then the number of jobs is set to the number of cores. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. {random_state} @@ -126,7 +129,7 @@ def __init__( warm_start=False, sampling_strategy="auto", replacement=False, - n_jobs=1, + n_jobs=None, random_state=None, verbose=0, ): diff --git a/imblearn/ensemble/_forest.py b/imblearn/ensemble/_forest.py index 68769d12e..db17c4a11 100644 --- a/imblearn/ensemble/_forest.py +++ b/imblearn/ensemble/_forest.py @@ -161,9 +161,12 @@ class BalancedRandomForestClassifier(RandomForestClassifier): replacement : bool, optional (default=False) Whether or not to sample randomly with replacement or not. - n_jobs : int, optional (default=1) - The number of jobs to run in parallel for both `fit` and `predict`. - If -1, then the number of jobs is set to the number of cores. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. {random_state} @@ -299,7 +302,7 @@ def __init__( oob_score=False, sampling_strategy="auto", replacement=False, - n_jobs=1, + n_jobs=None, random_state=None, verbose=0, warm_start=False, diff --git a/imblearn/over_sampling/_adasyn.py b/imblearn/over_sampling/_adasyn.py index 507ddfd25..a7ea9104b 100644 --- a/imblearn/over_sampling/_adasyn.py +++ b/imblearn/over_sampling/_adasyn.py @@ -38,8 +38,12 @@ class ADASYN(BaseOverSampler): :class:`sklearn.neighbors.base.KNeighborsMixin` that will be used to find the k_neighbors. - n_jobs : int, optional (default=1) - Number of threads to run the algorithm when it is possible. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. Notes ----- @@ -83,7 +87,7 @@ def __init__( sampling_strategy="auto", random_state=None, n_neighbors=5, - n_jobs=1, + n_jobs=None, ): super().__init__(sampling_strategy=sampling_strategy) self.random_state = random_state diff --git a/imblearn/over_sampling/_smote.py b/imblearn/over_sampling/_smote.py index 4798efadf..a81c492bf 100644 --- a/imblearn/over_sampling/_smote.py +++ b/imblearn/over_sampling/_smote.py @@ -40,7 +40,7 @@ def __init__( sampling_strategy="auto", random_state=None, k_neighbors=5, - n_jobs=1, + n_jobs=None, ): super().__init__(sampling_strategy=sampling_strategy) self.random_state = random_state @@ -252,8 +252,12 @@ class BorderlineSMOTE(BaseSMOTE): :class:`sklearn.neighbors.base.KNeighborsMixin` that will be used to find the k_neighbors. - n_jobs : int, optional (default=1) - The number of threads to open if possible. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. m_neighbors : int or object, optional (default=10) If int, number of nearest neighbours to use to determine if a minority @@ -316,7 +320,7 @@ def __init__( sampling_strategy="auto", random_state=None, k_neighbors=5, - n_jobs=1, + n_jobs=None, m_neighbors=10, kind="borderline-1", ): @@ -446,8 +450,12 @@ class SVMSMOTE(BaseSMOTE): :class:`sklearn.neighbors.base.KNeighborsMixin` that will be used to find the k_neighbors. - n_jobs : int, optional (default=1) - The number of threads to open if possible. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. m_neighbors : int or object, optional (default=10) If int, number of nearest neighbours to use to determine if a minority @@ -512,7 +520,7 @@ def __init__( sampling_strategy="auto", random_state=None, k_neighbors=5, - n_jobs=1, + n_jobs=None, m_neighbors=10, svm_estimator=None, out_step=0.5, @@ -661,8 +669,12 @@ class SMOTE(BaseSMOTE): :class:`sklearn.neighbors.base.KNeighborsMixin` that will be used to find the k_neighbors. - n_jobs : int, optional (default=1) - The number of threads to open if possible. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. Notes ----- @@ -711,7 +723,7 @@ def __init__( sampling_strategy="auto", random_state=None, k_neighbors=5, - n_jobs=1, + n_jobs=None, ): super().__init__( sampling_strategy=sampling_strategy, @@ -822,8 +834,12 @@ class SMOTENC(SMOTE): :class:`sklearn.neighbors.base.KNeighborsMixin` that will be used to find the k_neighbors. - n_jobs : int, optional (default=1) - The number of threads to open if possible. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. Notes ----- @@ -881,7 +897,7 @@ def __init__( sampling_strategy="auto", random_state=None, k_neighbors=5, - n_jobs=1, + n_jobs=None, ): super().__init__( sampling_strategy=sampling_strategy, @@ -1068,8 +1084,12 @@ class KMeansSMOTE(BaseSMOTE): :class:`sklearn.neighbors.base.KNeighborsMixin` that will be used to find the k_neighbors. - n_jobs : int, optional (default=1) - The number of threads to open if possible. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. kmeans_estimator : int or object, optional (default=MiniBatchKMeans()) A KMeans instance or the number of clusters to be used. By default, @@ -1134,7 +1154,7 @@ def __init__( sampling_strategy="auto", random_state=None, k_neighbors=2, - n_jobs=1, + n_jobs=None, kmeans_estimator=None, cluster_balance_threshold="auto", density_exponent="auto", diff --git a/imblearn/under_sampling/_prototype_generation/_cluster_centroids.py b/imblearn/under_sampling/_prototype_generation/_cluster_centroids.py index 98054e4fa..1c079d1a6 100644 --- a/imblearn/under_sampling/_prototype_generation/_cluster_centroids.py +++ b/imblearn/under_sampling/_prototype_generation/_cluster_centroids.py @@ -59,8 +59,12 @@ class ClusterCentroids(BaseUnderSampler): .. versionadded:: 0.3.0 - n_jobs : int, optional (default=1) - The number of threads to open if possible. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. Notes ----- @@ -92,7 +96,7 @@ def __init__( random_state=None, estimator=None, voting="auto", - n_jobs=1, + n_jobs=None, ): super().__init__(sampling_strategy=sampling_strategy) self.random_state = random_state diff --git a/imblearn/under_sampling/_prototype_selection/_condensed_nearest_neighbour.py b/imblearn/under_sampling/_prototype_selection/_condensed_nearest_neighbour.py index 9b0bea3c8..c47adbcac 100644 --- a/imblearn/under_sampling/_prototype_selection/_condensed_nearest_neighbour.py +++ b/imblearn/under_sampling/_prototype_selection/_condensed_nearest_neighbour.py @@ -46,8 +46,12 @@ class CondensedNearestNeighbour(BaseCleaningSampler): n_seeds_S : int, optional (default=1) Number of samples to extract in order to build the set S. - n_jobs : int, optional (default=1) - The number of threads to open if possible. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. Attributes ---------- @@ -97,7 +101,7 @@ def __init__( random_state=None, n_neighbors=None, n_seeds_S=1, - n_jobs=1, + n_jobs=None, ): super().__init__(sampling_strategy=sampling_strategy) self.random_state = random_state diff --git a/imblearn/under_sampling/_prototype_selection/_edited_nearest_neighbours.py b/imblearn/under_sampling/_prototype_selection/_edited_nearest_neighbours.py index 94aef0268..fc14524a3 100644 --- a/imblearn/under_sampling/_prototype_selection/_edited_nearest_neighbours.py +++ b/imblearn/under_sampling/_prototype_selection/_edited_nearest_neighbours.py @@ -47,8 +47,12 @@ class EditedNearestNeighbours(BaseCleaningSampler): - If ``'mode'``, the majority vote of the neighbours will be used in order to exclude a sample. - n_jobs : int, optional (default=1) - The number of threads to open if possible. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. Attributes ---------- @@ -94,7 +98,7 @@ class EditedNearestNeighbours(BaseCleaningSampler): """ def __init__( - self, sampling_strategy="auto", n_neighbors=3, kind_sel="all", n_jobs=1 + self, sampling_strategy="auto", n_neighbors=3, kind_sel="all", n_jobs=None ): super().__init__(sampling_strategy=sampling_strategy) self.n_neighbors = n_neighbors @@ -184,8 +188,12 @@ class RepeatedEditedNearestNeighbours(BaseCleaningSampler): - If ``'mode'``, the majority vote of the neighbours will be used in order to exclude a sample. - n_jobs : int, optional (default=1) - The number of thread to open when it is possible. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. Attributes ---------- @@ -236,7 +244,7 @@ def __init__( n_neighbors=3, max_iter=100, kind_sel="all", - n_jobs=1, + n_jobs=None, ): super().__init__(sampling_strategy=sampling_strategy) self.n_neighbors = n_neighbors @@ -354,8 +362,12 @@ class without early stopping. .. versionadded:: 0.3 - n_jobs : int, optional (default=1) - The number of thread to open when it is possible. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. Attributes ---------- @@ -407,7 +419,7 @@ def __init__( n_neighbors=3, kind_sel="all", allow_minority=False, - n_jobs=1, + n_jobs=None, ): super().__init__(sampling_strategy=sampling_strategy) self.n_neighbors = n_neighbors diff --git a/imblearn/under_sampling/_prototype_selection/_instance_hardness_threshold.py b/imblearn/under_sampling/_prototype_selection/_instance_hardness_threshold.py index 16d69056b..2bdd1c914 100644 --- a/imblearn/under_sampling/_prototype_selection/_instance_hardness_threshold.py +++ b/imblearn/under_sampling/_prototype_selection/_instance_hardness_threshold.py @@ -48,8 +48,12 @@ class InstanceHardnessThreshold(BaseUnderSampler): cv : int, optional (default=5) Number of folds to be used when estimating samples' instance hardness. - n_jobs : int, optional (default=1) - The number of threads to open if possible. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. Attributes ---------- @@ -95,7 +99,7 @@ def __init__( sampling_strategy="auto", random_state=None, cv=5, - n_jobs=1, + n_jobs=None, ): super().__init__(sampling_strategy=sampling_strategy) self.random_state = random_state diff --git a/imblearn/under_sampling/_prototype_selection/_nearmiss.py b/imblearn/under_sampling/_prototype_selection/_nearmiss.py index 5f76a34cf..b8ccb91b7 100644 --- a/imblearn/under_sampling/_prototype_selection/_nearmiss.py +++ b/imblearn/under_sampling/_prototype_selection/_nearmiss.py @@ -44,8 +44,12 @@ class NearMiss(BaseUnderSampler): :class:`sklearn.neighbors.base.KNeighborsMixin` that will be used to find the k_neighbors. - n_jobs : int, optional (default=1) - The number of threads to open if possible. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. Attributes ---------- @@ -91,7 +95,7 @@ def __init__( version=1, n_neighbors=3, n_neighbors_ver3=3, - n_jobs=1, + n_jobs=None, ): super().__init__(sampling_strategy=sampling_strategy) self.version = version diff --git a/imblearn/under_sampling/_prototype_selection/_neighbourhood_cleaning_rule.py b/imblearn/under_sampling/_prototype_selection/_neighbourhood_cleaning_rule.py index 0cd6daea4..05e077c38 100644 --- a/imblearn/under_sampling/_prototype_selection/_neighbourhood_cleaning_rule.py +++ b/imblearn/under_sampling/_prototype_selection/_neighbourhood_cleaning_rule.py @@ -47,8 +47,12 @@ class NeighbourhoodCleaningRule(BaseCleaningSampler): where Ci and C is the number of samples in the class and the data set, respectively and theta is the threshold. - n_jobs : int, optional (default=1) - The number of threads to open if possible. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. Attributes ---------- @@ -94,7 +98,7 @@ def __init__( n_neighbors=3, kind_sel="all", threshold_cleaning=0.5, - n_jobs=1, + n_jobs=None, ): super().__init__(sampling_strategy=sampling_strategy) self.n_neighbors = n_neighbors diff --git a/imblearn/under_sampling/_prototype_selection/_one_sided_selection.py b/imblearn/under_sampling/_prototype_selection/_one_sided_selection.py index aa37c0337..6bf093c56 100644 --- a/imblearn/under_sampling/_prototype_selection/_one_sided_selection.py +++ b/imblearn/under_sampling/_prototype_selection/_one_sided_selection.py @@ -43,8 +43,12 @@ class OneSidedSelection(BaseCleaningSampler): n_seeds_S : int, optional (default=1) Number of samples to extract in order to build the set S. - n_jobs : int, optional (default=1) - The number of threads to open if possible. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. Attributes ---------- @@ -91,7 +95,7 @@ def __init__( random_state=None, n_neighbors=None, n_seeds_S=1, - n_jobs=1, + n_jobs=None, ): super().__init__(sampling_strategy=sampling_strategy) self.random_state = random_state diff --git a/imblearn/under_sampling/_prototype_selection/_tomek_links.py b/imblearn/under_sampling/_prototype_selection/_tomek_links.py index 603930050..9eacf0367 100644 --- a/imblearn/under_sampling/_prototype_selection/_tomek_links.py +++ b/imblearn/under_sampling/_prototype_selection/_tomek_links.py @@ -25,8 +25,12 @@ class TomekLinks(BaseCleaningSampler): ---------- {sampling_strategy} - n_jobs : int, optional (default=1) - The number of threads to open if possible. + n_jobs : int or None, optional (default=None) + Number of CPU cores used during the cross-validation loop. + ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. + ``-1`` means using all processors. See + `Glossary `_ + for more details. Attributes ---------- @@ -66,7 +70,7 @@ class TomekLinks(BaseCleaningSampler): """ - def __init__(self, sampling_strategy="auto", n_jobs=1): + def __init__(self, sampling_strategy="auto", n_jobs=None): super().__init__(sampling_strategy=sampling_strategy) self.n_jobs = n_jobs