@@ -177,26 +177,40 @@ def test_lasso_path():
177
177
178
178
179
179
def test_enet_path ():
180
- X , y , X_test , y_test = build_dataset ()
180
+ # We use a large number of samples and of informative features so that
181
+ # the l1_ratio selected is more toward ridge than lasso
182
+ X , y , X_test , y_test = build_dataset (n_samples = 200 ,
183
+ n_features = 100 ,
184
+ n_informative_features = 100 )
181
185
max_iter = 150
182
186
183
187
with warnings .catch_warnings ():
184
188
# Here we have a small number of iterations, and thus the
185
189
# ElasticNet might not converge. This is to speed up tests
186
190
warnings .simplefilter ("ignore" , UserWarning )
187
- clf = ElasticNetCV (n_alphas = 5 , eps = 2e-3 , l1_ratio = [0.9 , 0.95 ], cv = 3 ,
191
+ clf = ElasticNetCV (n_alphas = 5 , eps = 2e-3 , l1_ratio = [0.5 , 0.7 ], cv = 3 ,
188
192
max_iter = max_iter )
189
193
clf .fit (X , y )
190
- assert_almost_equal (clf .alpha_ , 0.002 , 2 )
191
- assert_equal (clf .l1_ratio_ , 0.95 )
192
-
193
- clf = ElasticNetCV (n_alphas = 5 , eps = 2e-3 , l1_ratio = [0.9 , 0.95 ], cv = 3 ,
194
+ # Well-conditionned settings, we should have selected our
195
+ # smallest penalty
196
+ assert_almost_equal (clf .alpha_ , min (clf .alphas_ ))
197
+ # Non-sparse ground truth: we should have seleted an elastic-net
198
+ # that is closer to ridge
B091
than to lasso
199
+ assert_equal (clf .l1_ratio_ , min (clf .l1_ratio ))
200
+
201
+ clf = ElasticNetCV (n_alphas = 5 , eps = 2e-3 , l1_ratio = [0.5 , 0.7 ], cv = 3 ,
194
202
max_iter = max_iter , precompute = True )
195
203
clf .fit (X , y )
196
- assert_almost_equal (clf .alpha_ , 0.002 , 2 )
197
- assert_equal (clf .l1_ratio_ , 0.95 )
198
204
199
- # test set
205
+ # Well-conditionned settings, we should have selected our
206
+ # smallest penalty
207
+ assert_almost_equal (clf .alpha_ , min (clf .alphas_ ))
208
+ # Non-sparse ground truth: we should have seleted an elastic-net
209
+ # that is closer to ridge than to lasso
210
+ assert_equal (clf .l1_ratio_ , min (clf .l1_ratio ))
211
+
212
+ # We are in well-conditionned settings with low noise: we should
213
+ # have a good test-set performance
200
214
assert_greater (clf .score (X_test , y_test ), 0.99 )
201
215
202
216
0 commit comments