From ae403a08dfef5a435e7e57aa9cd3c73a3b29d921 Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Tue, 30 Aug 2016 22:16:05 +0200 Subject: [PATCH] Fix the warning in Nearmiss to inform the user about the number of samples issue --- imblearn/under_sampling/nearmiss.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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]