diff --git a/imblearn/under_sampling/nearmiss.py b/imblearn/under_sampling/nearmiss.py index e80461593..f6efda905 100644 --- a/imblearn/under_sampling/nearmiss.py +++ b/imblearn/under_sampling/nearmiss.py @@ -175,9 +175,11 @@ def _selection_dist_based(self, X, y, dist_vec, num_samples, key, # Throw a warning to tell the user that we did not have enough samples # to select and that we just select everything - warnings.warn('The number of the samples to be selected is larger than' - ' the number of samples available. The balancing ratio' - ' cannot be ensure and all samples will be returned.') + if len(sorted_idx) < num_samples: + warnings.warn('The number of the samples to be selected is larger' + ' than the number of samples available. The' + ' balancing ratio cannot be ensure and all samples' + ' will be returned.') # Select the desired number of samples sel_idx = sorted_idx[:num_samples]