@@ -84,6 +84,40 @@ def test_data_generate3(self):
8484 assert_allclose (y_train , y_train2 )
8585 assert_allclose (y_test , y_test2 )
8686
87+ def test_data_generate_outliers_have_spread (self ):
88+ # Regression test for GH #141: for certain seeds the internal offset
89+ # was drawn as 0, which collapsed every outlier onto the origin
90+ # (uniform(-0, 0) == 0) and produced zero-variance outliers. Sweep a
91+ # range of seeds (41, 48 and 50 previously triggered the collapse)
92+ # and confirm outliers always keep a non-zero spread.
93+ for seed in range (60 ):
94+ X , y = generate_data (
95+ n_features = 2 ,
96+ contamination = 0.05 ,
97+ train_only = True ,
98+ random_state = seed ,
99+ )
100+ outliers = X [y == 1 ]
101+ assert outliers .var () > 0 , \
102+ "outliers collapsed to zero variance for random_state=%d" % seed
103+
104+ def test_data_generate_reproducibility (self ):
105+ # Golden values pinned from the pre-fix implementation for seeds whose
106+ # offset was already non-zero. Redrawing only when the offset comes out
107+ # as 0 leaves these untouched, so this guards against a future change
108+ # silently altering long-standing fixed-seed output.
109+ golden = {
110+ 0 : ([5.059894904 , 5.061739412 ], [- 0.263919547 , 3.009107520 ]),
111+ 1 : ([3.401186423 , 3.524852969 ], [0.181525489 , 3.650202520 ]),
112+ 42 : ([6.433658544 , 5.509168303 ], [- 3.206743915 , - 4.912722786 ]),
113+ }
114+ for seed , (first , last ) in golden .items ():
115+ X , _ = generate_data (n_train = 10 , n_test = 5 , n_features = 2 ,
116+ contamination = 0.2 , train_only = True ,
117+ random_state = seed )
118+ assert_allclose (X [0 ], first , rtol = 0 , atol = 1e-9 )
119+ assert_allclose (X [- 1 ], last , rtol = 0 , atol = 1e-9 )
120+
87121 def test_data_generate_cluster (self ):
88122 X_train , X_test , y_train , y_test = \
89123 generate_data_clusters (n_train = self .n_train ,
0 commit comments