@@ -484,31 +484,35 @@ def test_n_components_upper_bounds(Estimator):
484
484
485
485
486
486
@pytest .mark .parametrize ("n_samples, n_features" , [(100 , 10 ), (100 , 200 )])
487
- @pytest .mark .parametrize ("seed" , range (10 ))
488
- def test_singular_value_helpers (n_samples , n_features , seed ):
487
+ def test_singular_value_helpers (n_samples , n_features , global_random_seed ):
489
488
# Make sure SVD and power method give approximately the same results
490
- X , Y = make_regression (n_samples , n_features , n_targets = 5 , random_state = seed )
489
+ X , Y = make_regression (
490
+ n_samples , n_features , n_targets = 5 , random_state = global_random_seed
491
+ )
491
492
u1 , v1 , _ = _get_first_singular_vectors_power_method (X , Y , norm_y_weights = True )
492
493
u2 , v2 = _get_first_singular_vectors_svd (X , Y )
493
494
494
495
_svd_flip_1d (u1 , v1 )
495
496
_svd_flip_1d (u2 , v2 )
496
497
497
- rtol = 1e-1
498
- assert_allclose (u1 , u2 , rtol = rtol )
499
- assert_allclose (v1 , v2 , rtol = rtol )
498
+ rtol = 1e-3
499
+ # Setting atol because some coordinates are very close to zero
500
+ assert_allclose (u1 , u2 , atol = u2 .max () * rtol )
501
+ assert_allclose (v1 , v2 , atol = v2 .max () * rtol )
500
502
501
503
502
- def test_one_component_equivalence ():
504
+ def test_one_component_equivalence (global_random_seed ):
503
505
# PLSSVD, PLSRegression and PLSCanonical should all be equivalent when
504
506
# n_components is 1
505
- X , Y = make_regression (100 , 10 , n_targets = 5 , random_state = 0 )
507
+ X , Y = make_regression (100 , 10 , n_targets = 5 , random_state = global_random_seed )
506
508
svd = PLSSVD (n_components = 1 ).fit (X , Y ).transform (X )
507
509
reg = PLSRegression (n_components = 1 ).fit (X , Y ).transform (X )
508
510
canonical = PLSCanonical (n_components = 1 ).fit (X , Y ).transform (X )
509
511
510
- assert_allclose (svd , reg , rtol = 1e-2 )
511
- assert_allclose (svd , canonical , rtol = 1e-2 )
512
+ rtol = 1e-3
513
+ # Setting atol because some entries are very close to zero
514
+ assert_allclose (svd , reg , atol = reg .max () * rtol )
515
+ assert_allclose (svd , canonical , atol = canonical .max () * rtol )
512
516
513
517
514
518
def test_svd_flip_1d ():
@@ -526,9 +530,11 @@ def test_svd_flip_1d():
526
530
assert_allclose (v , [- 1 , - 2 , - 3 ])
527
531
528
532
529
- def test_loadings_converges ():
533
+ def test_loadings_converges (global_random_seed ):
530
534
"""Test that CCA converges. Non-regression test for #19549."""
531
- X , y = make_regression (n_samples = 200 , n_features = 20 , n_targets = 20 , random_state = 20 )
535
+ X , y = make_regression (
536
+ n_samples = 200 , n_features = 20 , n_targets = 20 , random_state = global_random_seed
537
+ )
532
538
533
539
cca = CCA (n_components = 10 , max_iter = 500 )
534
540
0 commit comments