Skip to content

Commit c0e07cf

Browse files
authored
Fix seed sensitivity of test_fastica_eigh_low_rank_warning (scikit-learn#29612)
1 parent 0f3c9ff commit c0e07cf

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

doc/whats_new/v1.6.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ Changelog
165165
and automatic retries in case of HTTP errors. :pr:`29354` by :user:`Olivier
166166
Grisel <ogrisel>`.
167167

168+
:mod:`sklearn.decomposition`
169+
............................
170+
171+
- |Fix| Increase rank defficiency threshold in the whitening step of
172+
:class:`decomposition.FastICA` with `whiten_solver="eigh"` to improve the
173+
platform-agnosticity of the estimator. :pr:`29612` by :user:`Olivier Grisel
174+
<ogrisel>`.
175+
168176
:mod:`sklearn.discriminant_analysis`
169177
....................................
170178

sklearn/decomposition/_fastica.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ def g(x, fun_args):
605605
# Faster when num_samples >> n_features
606606
d, u = linalg.eigh(XT.dot(X))
607607
sort_indices = np.argsort(d)[::-1]
608-
eps = np.finfo(d.dtype).eps
608+
eps = np.finfo(d.dtype).eps * 10
609609
degenerate_idx = d < eps
610610
if np.any(degenerate_idx):
611611
warnings.warn(

sklearn/decomposition/tests/test_fastica.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from sklearn.decomposition import PCA, FastICA, fastica
1414
from sklearn.decomposition._fastica import _gs_decorrelation
1515
from sklearn.exceptions import ConvergenceWarning
16-
from sklearn.utils._testing import assert_allclose
16+
from sklearn.utils._testing import assert_allclose, ignore_warnings
1717

1818

1919
def center_and_norm(x, axis=-1):
@@ -448,5 +448,10 @@ def test_fastica_eigh_low_rank_warning(global_random_seed):
448448
X = A @ A.T
449449
ica = FastICA(random_state=0, whiten="unit-variance", whiten_solver="eigh")
450450
msg = "There are some small singular values"
451+
451452
with pytest.warns(UserWarning, match=msg):
452-
ica.fit(X)
453+
with ignore_warnings(category=ConvergenceWarning):
454+
# The FastICA solver may not converge for some data with specific
455+
# random seeds but this happens after the whiten step so this is
456+
# not want we want to test here.
457+
ica.fit(X)

0 commit comments

Comments
 (0)