@@ -88,7 +88,9 @@ def test_predict_iris():
88
88
LogisticRegression (C = len (iris .data ), solver = 'lbfgs' ,
89
89
multi_class = 'multinomial' ),
90
90
LogisticRegression (C = len (iris .data ), solver = 'newton-cg' ,
91
- multi_class = 'multinomial' )]:
91
+ multi_class = 'multinomial' ),
92
+ LogisticRegression (C = len (iris .data ), solver = 'sag' ,
93
+ multi_class = 'ovr' )]:
92
94
clf .fit (iris .data , target )
93
95
assert_array_equal (np .unique (target ), clf .classes_ )
94
96
@@ -199,17 +201,17 @@ def test_consistency_path():
199
201
f = ignore_warnings
200
202
# can't test with fit_intercept=True since LIBLINEAR
201
203
# penalizes the intercept
202
- for method in ('lbfgs' , 'newton-cg' , 'liblinear' ):
204
+ for method in ('lbfgs' , 'newton-cg' , 'liblinear' , 'sag' ):
203
205
coefs , Cs = f (logistic_regression_path )(
204
- X , y , Cs = Cs , fit_intercept = False , tol = 1e-16 , solver = method )
206
+ X , y , Cs = Cs , fit_intercept = False , tol = 1e-5 , solver = method )
205
207
for i , C in enumerate (Cs ):
206
- lr = LogisticRegression (C = C , fit_intercept = False , tol = 1e-16 )
208
+ lr = LogisticRegression (C = C , fit_intercept = False , tol = 1e-5 )
207
209
lr .fit (X , y )
208
210
lr_coef = lr .coef_ .ravel ()
209
211
assert_array_almost_equal (lr_coef , coefs [i ], decimal = 4 )
210
212
211
213
# test for fit_intercept=True
212
- for method in ('lbfgs' , 'newton-cg' , 'liblinear' ):
214
+ for method in ('lbfgs' , 'newton-cg' , 'liblinear' , 'sag' ):
213
215
Cs = [1e3 ]
214
216
coefs , Cs = f (logistic_regression_path )(
215
217
X , y , Cs = Cs , fit_intercept = True , tol = 1e-4 , solver = method )
@@ -434,29 +436,43 @@ def test_ovr_multinomial_iris():
434
436
435
437
def test_logistic_regression_solvers ():
436
438
X , y = make_classification (n_features = 10 , n_informative = 5 , random_state = 0 )
437
- clf_n = LogisticRegression (solver = 'newton-cg' , fit_intercept = False )
438
- clf_n .fit (X , y )
439
+ clf_new = LogisticRegression (solver = 'newton-cg' , fit_intercept = False )
440
+ clf_new .fit (X , y )
439
441
clf_lbf = LogisticRegression (solver = 'lbfgs' , fit_intercept = False )
440
442
clf_lbf .fit (X , y )
443
+ clf_sag = LogisticRegression (solver = 'sag' , fit_intercept = False )
444
+ clf_sag .fit (X , y )
441
445
clf_lib = LogisticRegression (fit_intercept = False )
442
446
clf_lib .fit (X , y )
443
- assert_array_almost_equal (clf_n .coef_ , clf_lib .coef_ , decimal = 3 )
447
+ assert_array_almost_equal (clf_new .coef_ , clf_lib .coef_ , decimal = 3 )
444
448
assert_array_almost_equal (clf_lib .coef_ , clf_lbf .coef_ , decimal = 3 )
445
- assert_array_almost_equal (clf_n .coef_ , clf_lbf .coef_ , decimal = 3 )
449
+ assert_array_almost_equal (clf_new .coef_ , clf_lbf .coef_ , decimal = 3 )
450
+ assert_array_almost_equal (clf_sag .coef_ , clf_lib .coef_ , decimal = 3 )
451
+ assert_array_almost_equal (clf_sag .coef_ , clf_new .coef_ , decimal = 3 )
452
+ assert_array_almost_equal (clf_sag .coef_ , clf_lbf .coef_ , decimal = 3 )
446
453
447
454
448
455
def test_logistic_regression_solvers_multiclass ():
456
+ tol = 1e-6
449
457
X , y = make_classification (n_samples = 20 , n_features = 20 , n_informative = 10 ,
450
458
n_classes = 3 , random_state = 0 )
451
- clf_n = LogisticRegression (solver = 'newton-cg' , fit_intercept = False )
452
- clf_n .fit (X , y )
453
- clf_lbf = LogisticRegression (solver = 'lbfgs' , fit_intercept = False )
459
+ clf_new = LogisticRegression (solver = 'newton-cg' , fit_intercept = False ,
460
+ tol = tol )
461
+ clf_new .fit (X , y )
462
+ clf_lbf = LogisticRegression (solver = 'lbfgs' , fit_intercept = False ,
463
+ tol = tol )
454
464
clf_lbf .fit (X , y )
455
- clf_lib = LogisticRegression (fit_intercept = False )
465
+ clf_sag = LogisticRegression (solver = 'sag' , fit_intercept = False ,
466
+ tol = tol , max_iter = 1000 )
467
+ clf_sag .fit (X , y )
468
+ clf_lib = LogisticRegression (fit_intercept = False , tol = tol )
456
469
clf_lib .fit (X , y )
457
- assert_array_almost_equal (clf_n .coef_ , clf_lib .coef_ , decimal = 4 )
470
+ assert_array_almost_equal (clf_new .coef_ , clf_lib .coef_ , decimal = 4 )
458
471
assert_array_almost_equal (clf_lib .coef_ , clf_lbf .coef_ , decimal = 4 )
459
- assert_array_almost_equal (clf_n .coef_ , clf_lbf .coef_ , decimal = 4 )
472
+ assert_array_almost_equal (clf_new .coef_ , clf_lbf .coef_ , decimal = 4 )
473
+ assert_array_almost_equal (clf_sag .coef_ , clf_lib .coef_ , decimal = 4 )
474
+ assert_array_almost_equal (clf_sag .coef_ , clf_new .coef_ , decimal = 4 )
475
+ assert_array_almost_equal (clf_sag .coef_ , clf_lbf .coef_ , decimal = 4 )
460
476
461
477
462
478
def test_logistic_regressioncv_class_weights ():
@@ -483,7 +499,12 @@ def test_logistic_regressioncv_class_weights():
483
499
clf_lib = LogisticRegressionCV (solver = 'liblinear' , fit_intercept = False ,
484
500
class_weight = 'auto' )
485
501
clf_lib .fit (X , y )
502
+ clf_sag = LogisticRegressionCV (solver = 'sag' , fit_intercept = False ,
503
+ class_weight = 'auto' )
504
+ clf_sag .fit (X , y )
486
505
assert_array_almost_equal (clf_lib .coef_ , clf_lbf .coef_ , decimal = 4 )
506
+ assert_array_almost_equal (clf_sag .coef_ , clf_lbf .coef_ , decimal = 4 )
507
+ assert_array_almost_equal (clf_lib .coef_ , clf_sag .coef_ , decimal = 4 )
487
508
488
509
489
510
def test_logistic_regression_convergence_warnings ():
0 commit comments