@@ -129,8 +129,7 @@ def __call__(self, model, X, y, sample_weight=None):
129
129
130
130
@skip_if_no_parallel
131
131
def test_lr_liblinear_warning ():
132
- n_samples , n_features = iris .data .shape
133
- target = iris .target_names [iris .target ]
132
+ X , y = make_classification (random_state = 0 )
134
133
135
134
lr = LogisticRegression (solver = "liblinear" , n_jobs = 2 )
136
135
warning_message = (
@@ -139,7 +138,7 @@ def test_lr_liblinear_warning():
139
138
" = 2."
140
139
)
141
140
with pytest .warns (UserWarning , match = warning_message ):
142
- lr .fit (iris . data , target )
141
+ lr .fit (X , y )
143
142
144
143
145
144
@pytest .mark .parametrize ("csr_container" , CSR_CONTAINERS )
@@ -148,8 +147,11 @@ def test_predict_3_classes(csr_container):
148
147
check_predictions (LogisticRegression (C = 10 ), csr_container (X ), Y2 )
149
148
150
149
151
- # TODO(1.7 ): remove filterwarnings after the deprecation of multi_class
150
+ # TODO(1.8 ): remove filterwarnings after the deprecation of multi_class
152
151
@pytest .mark .filterwarnings ("ignore:.*'multi_class' was deprecated.*:FutureWarning" )
152
+ @pytest .mark .filterwarnings (
153
+ "ignore:.*'liblinear' solver for multiclass classification is deprecated.*"
154
+ )
153
155
@pytest .mark .parametrize (
154
156
"clf" ,
155
157
[
@@ -197,7 +199,7 @@ def test_predict_iris(clf):
197
199
assert np .mean (pred == target ) > 0.95
198
200
199
201
200
- # TODO(1.7 ): remove filterwarnings after the deprecation of multi_class
202
+ # TODO(1.8 ): remove filterwarnings after the deprecation of multi_class
201
203
@pytest .mark .filterwarnings ("ignore:.*'multi_class' was deprecated.*:FutureWarning" )
202
204
@pytest .mark .parametrize ("LR" , [LogisticRegression , LogisticRegressionCV ])
203
205
def test_check_solver_option (LR ):
@@ -249,7 +251,7 @@ def test_elasticnet_l1_ratio_err_helpful(LR):
249
251
model .fit (np .array ([[1 , 2 ], [3 , 4 ]]), np .array ([0 , 1 ]))
250
252
251
253
252
- # TODO(1.7 ): remove whole test with deprecation of multi_class
254
+ # TODO(1.8 ): remove whole test with deprecation of multi_class
253
255
@pytest .mark .filterwarnings ("ignore:.*'multi_class' was deprecated.*:FutureWarning" )
254
256
@pytest .mark .parametrize ("solver" , ["lbfgs" , "newton-cg" , "sag" , "saga" ])
255
257
def test_multinomial_binary (solver ):
@@ -274,7 +276,7 @@ def test_multinomial_binary(solver):
274
276
assert np .mean (pred == target ) > 0.9
275
277
276
278
277
- # TODO(1.7 ): remove filterwarnings after the deprecation of multi_class
279
+ # TODO(1.8 ): remove filterwarnings after the deprecation of multi_class
278
280
# Maybe even remove this whole test as correctness of multinomial loss is tested
279
281
# elsewhere.
280
282
@pytest .mark .filterwarnings ("ignore:.*'multi_class' was deprecated.*:FutureWarning" )
@@ -614,7 +616,7 @@ def test_logistic_cv_sparse(csr_container):
614
616
assert clfs .C_ == clf .C_
615
617
616
618
617
- # TODO(1.7 ): remove filterwarnings after the deprecation of multi_class
619
+ # TODO(1.8 ): remove filterwarnings after the deprecation of multi_class
618
620
# Best remove this whole test.
619
621
@pytest .mark .filterwarnings ("ignore:.*'multi_class' was deprecated.*:FutureWarning" )
620
622
def test_ovr_multinomial_iris ():
@@ -700,7 +702,7 @@ def test_logistic_regression_solvers():
700
702
)
701
703
702
704
703
- # TODO(1.7 ): remove filterwarnings after the deprecation of multi_class
705
+ # TODO(1.8 ): remove filterwarnings after the deprecation of multi_class
704
706
@pytest .mark .filterwarnings ("ignore:.*'multi_class' was deprecated.*:FutureWarning" )
705
707
@pytest .mark .parametrize ("fit_intercept" , [False , True ])
706
708
def test_logistic_regression_solvers_multiclass (fit_intercept ):
@@ -1301,7 +1303,7 @@ def test_logreg_predict_proba_multinomial():
1301
1303
assert clf_wrong_loss > clf_multi_loss
1302
1304
1303
1305
1304
- # TODO(1.7 ): remove filterwarnings after the deprecation of multi_class
1306
+ # TODO(1.8 ): remove filterwarnings after the deprecation of multi_class
1305
1307
@pytest .mark .filterwarnings ("ignore:.*'multi_class' was deprecated.*:FutureWarning" )
1306
1308
@pytest .mark .parametrize ("max_iter" , np .arange (1 , 5 ))
1307
1309
@pytest .mark .parametrize ("multi_class" , ["ovr" , "multinomial" ])
@@ -1345,8 +1347,11 @@ def test_max_iter(max_iter, multi_class, solver, message):
1345
1347
assert lr .n_iter_ [0 ] == max_iter
1346
1348
1347
1349
1348
- # TODO(1.7 ): remove filterwarnings after the deprecation of multi_class
1350
+ # TODO(1.8 ): remove filterwarnings after the deprecation of multi_class
1349
1351
@pytest .mark .filterwarnings ("ignore:.*'multi_class' was deprecated.*:FutureWarning" )
1352
+ @pytest .mark .filterwarnings (
1353
+ "ignore:.*'liblinear' solver for multiclass classification is deprecated.*"
1354
+ )
1350
1355
@pytest .mark .parametrize ("solver" , SOLVERS )
1351
1356
def test_n_iter (solver ):
1352
1357
# Test that self.n_iter_ has the correct format.
@@ -1478,7 +1483,7 @@ def test_saga_vs_liblinear(csr_container):
1478
1483
assert_array_almost_equal (saga .coef_ , liblinear .coef_ , 3 )
1479
1484
1480
1485
1481
- # TODO(1.7 ): remove filterwarnings after the deprecation of multi_class
1486
+ # TODO(1.8 ): remove filterwarnings after the deprecation of multi_class
1482
1487
@pytest .mark .filterwarnings ("ignore:.*'multi_class' was deprecated.*:FutureWarning" )
1483
1488
@pytest .mark .parametrize ("multi_class" , ["ovr" , "multinomial" ])
1484
1489
@pytest .mark .parametrize (
@@ -1738,7 +1743,7 @@ def test_LogisticRegressionCV_GridSearchCV_elastic_net(n_classes):
1738
1743
assert gs .best_params_ ["C" ] == lrcv .C_ [0 ]
1739
1744
1740
1745
1741
- # TODO(1.7 ): remove filterwarnings after the deprecation of multi_class
1746
+ # TODO(1.8 ): remove filterwarnings after the deprecation of multi_class
1742
1747
# Maybe remove whole test after removal of the deprecated multi_class.
1743
1748
@pytest .mark .filterwarnings ("ignore:.*'multi_class' was deprecated.*:FutureWarning" )
1744
1749
def test_LogisticRegressionCV_GridSearchCV_elastic_net_ovr ():
@@ -1786,7 +1791,7 @@ def test_LogisticRegressionCV_GridSearchCV_elastic_net_ovr():
1786
1791
assert (lrcv .predict (X_test ) == gs .predict (X_test )).mean () >= 0.8
1787
1792
1788
1793
1789
- # TODO(1.7 ): remove filterwarnings after the deprecation of multi_class
1794
+ # TODO(1.8 ): remove filterwarnings after the deprecation of multi_class
1790
1795
@pytest .mark .filterwarnings ("ignore:.*'multi_class' was deprecated.*:FutureWarning" )
1791
1796
@pytest .mark .parametrize ("penalty" , ("l2" , "elasticnet" ))
1792
1797
@pytest .mark .parametrize ("multi_class" , ("ovr" , "multinomial" , "auto" ))
@@ -1825,7 +1830,7 @@ def test_LogisticRegressionCV_no_refit(penalty, multi_class):
1825
1830
assert lrcv .coef_ .shape == (n_classes , n_features )
1826
1831
1827
1832
1828
- # TODO(1.7 ): remove filterwarnings after the deprecation of multi_class
1833
+ # TODO(1.8 ): remove filterwarnings after the deprecation of multi_class
1829
1834
# Remove multi_class an change first element of the expected n_iter_.shape from
1830
1835
# n_classes to 1 (according to the docstring).
1831
1836
@pytest .mark .filterwarnings ("ignore:.*'multi_class' was deprecated.*:FutureWarning" )
@@ -1955,8 +1960,11 @@ def test_logistic_regression_path_coefs_multinomial():
1955
1960
assert_array_almost_equal (coefs [1 ], coefs [2 ], decimal = 1 )
1956
1961
1957
1962
1958
- # TODO(1.7 ): remove filterwarnings after the deprecation of multi_class
1963
+ # TODO(1.8 ): remove filterwarnings after the deprecation of multi_class
1959
1964
@pytest .mark .filterwarnings ("ignore:.*'multi_class' was deprecated.*:FutureWarning" )
1965
+ @pytest .mark .filterwarnings (
1966
+ "ignore:.*'liblinear' solver for multiclass classification is deprecated.*"
1967
+ )
1960
1968
@pytest .mark .parametrize (
1961
1969
"est" ,
1962
1970
[
@@ -2126,7 +2134,7 @@ def test_scores_attribute_layout_elasticnet():
2126
2134
assert avg_scores_lrcv [i , j ] == pytest .approx (avg_score_lr )
2127
2135
2128
2136
2129
- # TODO(1.7 ): remove filterwarnings after the deprecation of multi_class
2137
+ # TODO(1.8 ): remove filterwarnings after the deprecation of multi_class
2130
2138
@pytest .mark .filterwarnings ("ignore:.*'multi_class' was deprecated.*:FutureWarning" )
2131
2139
@pytest .mark .parametrize ("solver" , ["lbfgs" , "newton-cg" , "newton-cholesky" ])
2132
2140
@pytest .mark .parametrize ("fit_intercept" , [False , True ])
@@ -2171,7 +2179,7 @@ def test_multinomial_identifiability_on_iris(solver, fit_intercept):
2171
2179
assert clf .intercept_ .sum (axis = 0 ) == pytest .approx (0 , abs = 1e-11 )
2172
2180
2173
2181
2174
- # TODO(1.7 ): remove filterwarnings after the deprecation of multi_class
2182
+ # TODO(1.8 ): remove filterwarnings after the deprecation of multi_class
2175
2183
@pytest .mark .filterwarnings ("ignore:.*'multi_class' was deprecated.*:FutureWarning" )
2176
2184
@pytest .mark .parametrize ("multi_class" , ["ovr" , "multinomial" , "auto" ])
2177
2185
@pytest .mark .parametrize ("class_weight" , [{0 : 1.0 , 1 : 10.0 , 2 : 1.0 }, "balanced" ])
@@ -2349,7 +2357,7 @@ def test_passing_params_without_enabling_metadata_routing():
2349
2357
lr_cv .score (X , y , ** params )
2350
2358
2351
2359
2352
- # TODO(1.7 ): remove
2360
+ # TODO(1.8 ): remove
2353
2361
def test_multi_class_deprecated ():
2354
2362
"""Check `multi_class` parameter deprecated."""
2355
2363
X , y = make_classification (n_classes = 3 , n_samples = 50 , n_informative = 6 )
@@ -2414,3 +2422,18 @@ def test_newton_cholesky_fallback_to_lbfgs(global_random_seed):
2414
2422
n_iter_nc_limited = lr_nc_limited .n_iter_ [0 ]
2415
2423
2416
2424
assert n_iter_nc_limited == lr_nc_limited .max_iter - 1
2425
+
2426
+
2427
+ # TODO(1.8): check for an error instead
2428
+ @pytest .mark .parametrize ("Estimator" , [LogisticRegression , LogisticRegressionCV ])
2429
+ def test_liblinear_multiclass_warning (Estimator ):
2430
+ """Check that liblinear warns on multiclass problems."""
2431
+ msg = (
2432
+ "Using the 'liblinear' solver for multiclass classification is "
2433
+ "deprecated. An error will be raised in 1.8. Either use another "
2434
+ "solver which supports the multinomial loss or wrap the estimator "
2435
+ "in a OneVsRestClassifier to keep applying a one-versus-rest "
2436
+ "scheme."
2437
+ )
2438
+ with pytest .warns (FutureWarning , match = msg ):
2439
+ Estimator (solver = "liblinear" ).fit (iris .data , iris .target )
0 commit comments