From e8af7e5bad40317f706a683c3c77f6ebec40dbec Mon Sep 17 00:00:00 2001 From: JanekBlankenburg <73780408+JanekBlankenburg@users.noreply.github.com> Date: Fri, 19 Aug 2022 14:43:12 +0200 Subject: [PATCH] Adjustment of the validation of the number of target neighbors Adjustment of the validation of the number of target neighbors to fit the original LMNN definition by Weinberger et al. and by that prevent unexpected behavior for small classes. --- metric_learn/lmnn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metric_learn/lmnn.py b/metric_learn/lmnn.py index 47bb065f..7865cbe5 100644 --- a/metric_learn/lmnn.py +++ b/metric_learn/lmnn.py @@ -172,7 +172,7 @@ def fit(self, X, y): self.verbose, random_state=self.random_state) required_k = np.bincount(label_inds).min() - if self.n_neighbors > required_k: + if self.n_neighbors >= required_k: raise ValueError('not enough class labels for specified k' ' (smallest class has %d)' % required_k)