4
4
import numpy as np
5
5
import pytest
6
6
from numpy .testing import assert_allclose
7
- from scipy import sparse
8
7
9
8
from sklearn .base import BaseEstimator , clone
10
9
from sklearn .calibration import (
48
47
assert_array_equal ,
49
48
)
50
49
from sklearn .utils .extmath import softmax
50
+ from sklearn .utils .fixes import CSR_CONTAINERS
51
51
52
52
N_SAMPLES = 200
53
53
@@ -58,9 +58,10 @@ def data():
58
58
return X , y
59
59
60
60
61
+ @pytest .mark .parametrize ("csr_container" , CSR_CONTAINERS )
61
62
@pytest .mark .parametrize ("method" , ["sigmoid" , "isotonic" ])
62
63
@pytest .mark .parametrize ("ensemble" , [True , False ])
63
- def test_calibration (data , method , ensemble ):
64
+ def test_calibration (data , method , csr_container , ensemble ):
64
65
# Test calibration objects with isotonic and sigmoid
65
66
n_samples = N_SAMPLES // 2
66
67
X , y = data
@@ -83,7 +84,7 @@ def test_calibration(data, method, ensemble):
83
84
# Naive Bayes with calibration
84
85
for this_X_train , this_X_test in [
85
86
(X_train , X_test ),
86
- (sparse . csr_matrix (X_train ), sparse . csr_matrix (X_test )),
87
+ (csr_container (X_train ), csr_container (X_test )),
87
88
]:
88
89
cal_clf = CalibratedClassifierCV (clf , method = method , cv = 5 , ensemble = ensemble )
89
90
# Note that this fit overwrites the fit on the entire training
@@ -284,7 +285,8 @@ def predict(self, X):
284
285
assert_allclose (probas , 1.0 / clf .n_classes_ )
285
286
286
287
287
- def test_calibration_prefit ():
288
+ @pytest .mark .parametrize ("csr_container" , CSR_CONTAINERS )
289
+ def test_calibration_prefit (csr_container ):
288
290
"""Test calibration for prefitted classifiers"""
289
291
n_samples = 50
290
292
X , y = make_classification (n_samples = 3 * n_samples , n_features = 6 , random_state = 42 )
@@ -314,7 +316,7 @@ def test_calibration_prefit():
314
316
# Naive Bayes with calibration
315
317
for this_X_calib , this_X_test in [
316
318
(X_calib , X_test ),
317
- (sparse . csr_matrix (X_calib ), sparse . csr_matrix (X_test )),
319
+ (csr_container (X_calib ), csr_container (X_test )),
318
320
]:
319
321
for method in ["isotonic" , "sigmoid" ]:
320
322
cal_clf = CalibratedClassifierCV (clf , method = method , cv = "prefit" )
0 commit comments