From c0d47af339d3728c42468071f3b9a419b7d1fb29 Mon Sep 17 00:00:00 2001 From: Julien Jerphanion Date: Wed, 27 Oct 2021 15:04:59 +0200 Subject: [PATCH] Inject placeholder value for MeanShift.bandwidth MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This modify the test configuration so that it makes sense for when a sole sample is provided for MeanShift. This test was passing previously for this configuration but was not supposed to. The new implementation strategy for kneighbors which uses PairwiseDistancesArgKmin (see #21462) is numerically stabler for this case, motivating this modication. Co-authored-by: Guillaume Lemaitre Co-authored-by: Jérémie du Boisberranger --- sklearn/utils/estimator_checks.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sklearn/utils/estimator_checks.py b/sklearn/utils/estimator_checks.py index ccc6ff23ed8fc..517680acdc88a 100644 --- a/sklearn/utils/estimator_checks.py +++ b/sklearn/utils/estimator_checks.py @@ -632,6 +632,11 @@ def _set_checking_parameters(estimator): if "n_init" in params: # K-Means estimator.set_params(n_init=2) + if name == "MeanShift": + # In the case of check_fit2d_1sample, bandwidth is set to None and + # is thus estimated. De facto it is 0.0 as a single sample is provided + # and this makes the test fails. Hence we give it a placeholder value. + estimator.set_params(bandwidth=1.0) if name == "TruncatedSVD": # TruncatedSVD doesn't run with n_components = n_features