22
22
23
23
@pytest .mark .parametrize ("svd_solver" , ["full" , "auto" , "randomized" ])
24
24
@pytest .mark .parametrize ("batch_number" , [3 , 10 ])
25
+ @pytest .mark .filterwarnings ("ignore:invalid value:RuntimeWarning" )
25
26
def test_compare_with_sklearn (svd_solver , batch_number ):
26
27
X = iris .data
27
28
X_da = da .from_array (X , chunks = (3 , - 1 ))
@@ -52,14 +53,15 @@ def test_compare_with_sklearn(svd_solver, batch_number):
52
53
53
54
54
55
@pytest .mark .parametrize ("svd_solver" , ["full" , "auto" , "randomized" ])
56
+ @pytest .mark .filterwarnings ("ignore:invalid value:RuntimeWarning" )
55
57
def test_incremental_pca (svd_solver ):
56
58
# Incremental PCA on dense arrays.
57
59
X = iris .data
58
60
X = da .from_array (X , chunks = (3 , - 1 ))
59
61
batch_size = X .shape [0 ] // 3
60
62
ipca = IncrementalPCA (n_components = 2 , batch_size = batch_size , svd_solver = svd_solver )
61
63
pca = PCA (n_components = 2 , svd_solver = svd_solver )
62
- pca .fit_transform (X )
64
+ pca .fit_transform (X . compute () )
63
65
64
66
X_transformed = ipca .fit_transform (X )
65
67
@@ -87,6 +89,7 @@ def test_incremental_pca(svd_solver):
87
89
)
88
90
89
91
92
+ @pytest .mark .filterwarnings ("ignore:invalid value:RuntimeWarning" )
90
93
def test_incremental_pca_check_projection ():
91
94
# Test that the projection of data is correct.
92
95
rng = np .random .RandomState (1999 )
@@ -111,6 +114,7 @@ def test_incremental_pca_check_projection():
111
114
assert_almost_equal (np .abs (Yt [0 ][0 ]), 1.0 , 1 )
112
115
113
116
117
+ @pytest .mark .filterwarnings ("ignore:invalid value:RuntimeWarning" )
114
118
def test_incremental_pca_inverse ():
115
119
# Test that the projection of data can be inverted.
116
120
rng = np .random .RandomState (1999 )
@@ -154,6 +158,7 @@ def test_incremental_pca_validation():
154
158
IncrementalPCA (n_components = n_components ).partial_fit (X )
155
159
156
160
161
+ @pytest .mark .filterwarnings ("ignore:invalid value:RuntimeWarning" )
157
162
def test_n_components_none ():
158
163
# Ensures that n_components == None is handled correctly
159
164
rng = np .random .RandomState (1999 )
@@ -173,6 +178,7 @@ def test_n_components_none():
173
178
assert ipca .n_components_ == ipca .components_ .shape [0 ]
174
179
175
180
181
+ @pytest .mark .filterwarnings ("ignore:invalid value:RuntimeWarning" )
176
182
def test_incremental_pca_set_params ():
177
183
# Test that components_ sign is stable over batch sizes.
178
184
rng = np .random .RandomState (1999 )
@@ -200,6 +206,7 @@ def test_incremental_pca_set_params():
200
206
ipca .partial_fit (X )
201
207
202
208
209
+ @pytest .mark .filterwarnings ("ignore:invalid value:RuntimeWarning" )
203
210
def test_incremental_pca_num_features_change ():
204
211
# Test that changing n_components will raise an error.
205
212
rng = np .random .RandomState (1999 )
@@ -215,6 +222,7 @@ def test_incremental_pca_num_features_change():
215
222
ipca .partial_fit (X2 )
216
223
217
224
225
+ @pytest .mark .filterwarnings ("ignore:invalid value:RuntimeWarning" )
218
226
def test_incremental_pca_batch_signs ():
219
227
# Test that components_ sign is stable over batch sizes.
220
228
rng = np .random .RandomState (1999 )
@@ -232,6 +240,7 @@ def test_incremental_pca_batch_signs():
232
240
assert_almost_equal (np .sign (i ), np .sign (j ), decimal = 6 )
233
241
234
242
243
+ @pytest .mark .filterwarnings ("ignore:invalid value:RuntimeWarning" )
235
244
def test_incremental_pca_batch_values ():
236
245
# Test that components_ values are stable over batch sizes.
237
246
rng = np .random .RandomState (1999 )
@@ -249,6 +258,7 @@ def test_incremental_pca_batch_values():
249
258
assert_almost_equal (i , j , decimal = 1 )
250
259
251
260
261
+ @pytest .mark .filterwarnings ("ignore:invalid value:RuntimeWarning" )
252
262
def test_incremental_pca_batch_rank ():
253
263
# Test sample size in each batch is always larger or equal to n_components
254
264
rng = np .random .RandomState (1999 )
@@ -266,6 +276,7 @@ def test_incremental_pca_batch_rank():
266
276
assert_allclose_dense_sparse (components_i , components_j )
267
277
268
278
279
+ @pytest .mark .filterwarnings ("ignore:invalid value:RuntimeWarning" )
269
280
def test_incremental_pca_partial_fit ():
270
281
# Test that fit and partial_fit get equivalent results.
271
282
rng = np .random .RandomState (1999 )
@@ -288,12 +299,13 @@ def test_incremental_pca_partial_fit():
288
299
289
300
290
301
@pytest .mark .parametrize ("svd_solver" , ["full" , "auto" , "randomized" ])
302
+ @pytest .mark .filterwarnings ("ignore:invalid value:RuntimeWarning" )
291
303
def test_incremental_pca_against_pca_iris (svd_solver ):
292
304
# Test that IncrementalPCA and PCA are approximate (to a sign flip).
293
305
X = iris .data
294
306
X = da .from_array (X , chunks = [50 , - 1 ])
295
307
296
- Y_pca = PCA (n_components = 2 , svd_solver = svd_solver ).fit_transform (X )
308
+ Y_pca = PCA (n_components = 2 , svd_solver = svd_solver ).fit_transform (X . compute () )
297
309
Y_ipca = IncrementalPCA (
298
310
n_components = 2 , batch_size = 25 , svd_solver = svd_solver
299
311
).fit_transform (X )
@@ -302,6 +314,7 @@ def test_incremental_pca_against_pca_iris(svd_solver):
302
314
303
315
304
316
@pytest .mark .parametrize ("svd_solver" , ["full" , "auto" , "randomized" ])
317
+ @pytest .mark .filterwarnings ("ignore:invalid value:RuntimeWarning" )
305
318
def test_incremental_pca_against_pca_random_data (svd_solver ):
306
319
# Test that IncrementalPCA and PCA are approximate (to a sign flip).
307
320
rng = np .random .RandomState (1999 )
@@ -310,7 +323,7 @@ def test_incremental_pca_against_pca_random_data(svd_solver):
310
323
X = rng .randn (n_samples , n_features ) + 5 * rng .rand (1 , n_features )
311
324
X = da .from_array (X , chunks = [40 , - 1 ])
312
325
313
- Y_pca = PCA (n_components = 3 , svd_solver = svd_solver ).fit_transform (X )
326
+ Y_pca = PCA (n_components = 3 , svd_solver = svd_solver ).fit_transform (X . compute () )
314
327
Y_ipca = IncrementalPCA (
315
328
n_components = 3 , batch_size = 25 , svd_solver = svd_solver
316
329
).fit_transform (X )
@@ -319,6 +332,7 @@ def test_incremental_pca_against_pca_random_data(svd_solver):
319
332
320
333
321
334
@pytest .mark .parametrize ("svd_solver" , ["full" , "auto" , "randomized" ])
335
+ @pytest .mark .filterwarnings ("ignore:invalid value:RuntimeWarning" )
322
336
def test_explained_variances (svd_solver ):
323
337
# Test that PCA and IncrementalPCA calculations match
324
338
X = datasets .make_low_rank_matrix (
@@ -328,7 +342,7 @@ def test_explained_variances(svd_solver):
328
342
prec = 3
329
343
n_samples , n_features = X .shape
330
344
for nc in [None , 99 ]:
331
- pca = PCA (n_components = nc , svd_solver = svd_solver ).fit (X )
345
+ pca = PCA (n_components = nc , svd_solver = svd_solver ).fit (X . compute () )
332
346
ipca = IncrementalPCA (
333
347
n_components = nc , batch_size = 100 , svd_solver = svd_solver
334
348
).fit (X )
@@ -342,6 +356,7 @@ def test_explained_variances(svd_solver):
342
356
343
357
344
358
@pytest .mark .parametrize ("svd_solver" , ["full" , "auto" , "randomized" ])
359
+ @pytest .mark .filterwarnings ("ignore:invalid value:RuntimeWarning" )
345
360
def test_singular_values (svd_solver ):
346
361
# Check that the IncrementalPCA output has the correct singular values
347
362
@@ -354,7 +369,7 @@ def test_singular_values(svd_solver):
354
369
)
355
370
X = da .from_array (X , chunks = [200 , - 1 ])
356
371
357
- pca = PCA (n_components = 10 , svd_solver = svd_solver , random_state = rng ).fit (X )
372
+ pca = PCA (n_components = 10 , svd_solver = svd_solver , random_state = rng ).fit (X . compute () )
358
373
ipca = IncrementalPCA (n_components = 10 , batch_size = 100 , svd_solver = svd_solver ).fit (X )
359
374
assert_array_almost_equal (pca .singular_values_ , ipca .singular_values_ , 2 )
360
375
@@ -389,7 +404,7 @@ def test_singular_values(svd_solver):
389
404
pca = PCA (n_components = 3 , svd_solver = svd_solver , random_state = rng )
390
405
ipca = IncrementalPCA (n_components = 3 , batch_size = 100 , svd_solver = svd_solver )
391
406
392
- X_pca = pca .fit_transform (X )
407
+ X_pca = pca .fit_transform (X . compute () )
393
408
X_pca /= np .sqrt (np .sum (X_pca ** 2.0 , axis = 0 ))
394
409
X_pca [:, 0 ] *= 3.142
395
410
X_pca [:, 1 ] *= 2.718
@@ -403,6 +418,7 @@ def test_singular_values(svd_solver):
403
418
404
419
405
420
@pytest .mark .parametrize ("svd_solver" , ["full" , "auto" , "randomized" ])
421
+ @pytest .mark .filterwarnings ("ignore:invalid value:RuntimeWarning" )
406
422
def test_whitening (svd_solver ):
407
423
# Test that PCA and IncrementalPCA transforms match to sign flip.
408
424
X = datasets .make_low_rank_matrix (
@@ -412,7 +428,7 @@ def test_whitening(svd_solver):
412
428
prec = 3
413
429
n_samples , n_features = X .shape
414
430
for nc in [None , 9 ]:
415
- pca = PCA (whiten = True , n_components = nc , svd_solver = svd_solver ).fit (X )
431
+ pca = PCA (whiten = True , n_components = nc , svd_solver = svd_solver ).fit (X . compute () )
416
432
ipca = IncrementalPCA (
417
433
whiten = True , n_components = nc , batch_size = 250 , svd_solver = svd_solver
418
434
).fit (X )
@@ -427,6 +443,7 @@ def test_whitening(svd_solver):
427
443
assert_almost_equal (Xinv_pca , Xinv_ipca , decimal = prec )
428
444
429
445
446
+ @pytest .mark .filterwarnings ("ignore:invalid value:RuntimeWarning" )
430
447
def test_incremental_pca_partial_fit_float_division ():
431
448
# Test to ensure float division is used in all versions of Python
432
449
# (non-regression test for issue #9489)
0 commit comments