13
13
from sklearn .utils ._testing import (assert_array_almost_equal ,
14
14
assert_almost_equal ,
15
15
assert_array_equal ,
16
- assert_raises , ignore_warnings )
16
+ ignore_warnings )
17
17
from sklearn .utils .extmath import softmax
18
18
from sklearn .exceptions import NotFittedError
19
19
from sklearn .datasets import make_classification , make_blobs
@@ -60,7 +60,8 @@ def test_calibration(data, method, ensemble):
60
60
prob_pos_clf = clf .predict_proba (X_test )[:, 1 ]
61
61
62
62
cal_clf = CalibratedClassifierCV (clf , cv = y .size + 1 , ensemble = ensemble )
63
- assert_raises (ValueError , cal_clf .fit , X , y )
63
+ with pytest .raises (ValueError ):
64
+ cal_clf .fit (X , y )
64
65
65
66
# Naive Bayes with calibration
66
67
for this_X_train , this_X_test in [(X_train , X_test ),
@@ -386,8 +387,8 @@ def test_sigmoid_calibration():
386
387
387
388
# check that _SigmoidCalibration().fit only accepts 1d array or 2d column
388
389
# arrays
389
- assert_raises ( ValueError , _SigmoidCalibration (). fit ,
390
- np .vstack ((exF , exF )), exY )
390
+ with pytest . raises ( ValueError ):
391
+ _SigmoidCalibration (). fit ( np .vstack ((exF , exF )), exY )
391
392
392
393
393
394
def test_calibration_curve ():
@@ -406,8 +407,8 @@ def test_calibration_curve():
406
407
407
408
# probabilities outside [0, 1] should not be accepted when normalize
408
409
# is set to False
409
- assert_raises ( ValueError , calibration_curve , [ 1.1 ], [ - 0.1 ],
410
- normalize = False )
410
+ with pytest . raises ( ValueError ):
411
+ calibration_curve ([ 1.1 ], [ - 0.1 ], normalize = False )
411
412
412
413
# test that quantiles work as expected
413
414
y_true2 = np .array ([0 , 0 , 0 , 0 , 1 , 1 ])
@@ -421,8 +422,8 @@ def test_calibration_curve():
421
422
assert_almost_equal (prob_pred_quantile , [0.1 , 0.8 ])
422
423
423
424
# Check that error is raised when invalid strategy is selected
424
- assert_raises (ValueError , calibration_curve , y_true2 , y_pred2 ,
425
- strategy = 'percentile' )
425
+ with pytest . raises (ValueError ):
426
+ calibration_curve ( y_true2 , y_pred2 , strategy = 'percentile' )
426
427
427
428
428
429
@pytest .mark .parametrize ('ensemble' , [True , False ])
0 commit comments