10
10
11
11
from sklearn .utils ._testing import assert_almost_equal
12
12
from sklearn .utils ._testing import assert_array_almost_equal
13
- from sklearn .utils ._testing import assert_warns
14
13
15
14
from sklearn .decomposition import FastICA , fastica , PCA
16
15
from sklearn .decomposition ._fastica import _gs_decorrelation
@@ -141,7 +140,9 @@ def test_fastica_nowhiten():
141
140
142
141
# test for issue #697
143
142
ica = FastICA (n_components = 1 , whiten = False , random_state = 0 )
144
- assert_warns (UserWarning , ica .fit , m )
143
+ warn_msg = "Ignoring n_components with whiten=False."
144
+ with pytest .warns (UserWarning , match = warn_msg ):
145
+ ica .fit (m )
145
146
assert hasattr (ica , 'mixing_' )
146
147
147
148
@@ -164,9 +165,14 @@ def test_fastica_convergence_fail():
164
165
m = np .dot (mixing , s )
165
166
166
167
# Do fastICA with tolerance 0. to ensure failing convergence
167
- ica = FastICA (algorithm = "parallel" , n_components = 2 , random_state = rng ,
168
- max_iter = 2 , tol = 0. )
169
- assert_warns (ConvergenceWarning , ica .fit , m .T )
168
+ warn_msg = (
169
+ "FastICA did not converge. Consider increasing tolerance "
170
+ "or the maximum number of iterations."
171
+ )
172
+ with pytest .warns (ConvergenceWarning , match = warn_msg ):
173
+ ica = FastICA (algorithm = "parallel" , n_components = 2 , random_state = rng ,
174
+ max_iter = 2 , tol = 0. )
175
+ ica .fit (m .T )
170
176
171
177
172
178
@pytest .mark .parametrize ('add_noise' , [True , False ])
0 commit comments