From 82a20b184ee4917e8dbcfc9f77a0f939d92a5079 Mon Sep 17 00:00:00 2001 From: mbatoul Date: Wed, 3 Mar 2021 21:19:34 +0100 Subject: [PATCH 1/3] Fix: RuntimeWarning in test_iforest_with_uniform_data --- sklearn/ensemble/_iforest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sklearn/ensemble/_iforest.py b/sklearn/ensemble/_iforest.py index 588b1bbef299c..74901cb6fc925 100644 --- a/sklearn/ensemble/_iforest.py +++ b/sklearn/ensemble/_iforest.py @@ -320,7 +320,8 @@ def predict(self, X): check_is_fitted(self) X = self._validate_data(X, accept_sparse='csr', reset=False) is_inlier = np.ones(X.shape[0], dtype=int) - is_inlier[self.decision_function(X) < 0] = -1 + #is_inlier[self.decision_function(X) < 0] = -1 + np.where(is_inlier < 0, -1, is_inlier) return is_inlier def decision_function(self, X): From 9ba3c87247ec00a29d3573f35ed77dfcd77410c8 Mon Sep 17 00:00:00 2001 From: mbatoul Date: Mon, 15 Mar 2021 21:51:58 +0100 Subject: [PATCH 2/3] remove np.where --- sklearn/ensemble/_iforest.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sklearn/ensemble/_iforest.py b/sklearn/ensemble/_iforest.py index 74901cb6fc925..588b1bbef299c 100644 --- a/sklearn/ensemble/_iforest.py +++ b/sklearn/ensemble/_iforest.py @@ -320,8 +320,7 @@ def predict(self, X): check_is_fitted(self) X = self._validate_data(X, accept_sparse='csr', reset=False) is_inlier = np.ones(X.shape[0], dtype=int) - #is_inlier[self.decision_function(X) < 0] = -1 - np.where(is_inlier < 0, -1, is_inlier) + is_inlier[self.decision_function(X) < 0] = -1 return is_inlier def decision_function(self, X): From 9e46b9780d7d366019a55a4923f079a1a716e5f0 Mon Sep 17 00:00:00 2001 From: mbatoul Date: Tue, 16 Mar 2021 18:54:58 +0100 Subject: [PATCH 3/3] Fix - LDA#_solve_svd: set explained variance ratio to empty array when max components is zero --- sklearn/discriminant_analysis.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sklearn/discriminant_analysis.py b/sklearn/discriminant_analysis.py index c5c18ac9136d2..2e80f94404175 100644 --- a/sklearn/discriminant_analysis.py +++ b/sklearn/discriminant_analysis.py @@ -476,8 +476,12 @@ def _solve_svd(self, X, y): # (n_classes) centers _, S, Vt = linalg.svd(X, full_matrices=0) - self.explained_variance_ratio_ = (S**2 / np.sum( - S**2))[:self._max_components] + if self._max_components == 0: + self.explained_variance_ratio_ = np.empty((0,), dtype=S.dtype) + else: + self.explained_variance_ratio_ = (S**2 / np.sum( + S**2))[:self._max_components] + rank = np.sum(S > self.tol * S[0]) self.scalings_ = np.dot(scalings, Vt.T[:, :rank]) coef = np.dot(self.means_ - self.xbar_, self.scalings_)