@@ -26,27 +26,27 @@ def build_data():
26
26
27
27
28
28
def build_pairs ():
29
- # test that you can do cross validation on a ConstrainedDataset with
29
+ # test that you can do cross validation on tuples of points with
30
30
# a WeaklySupervisedMetricLearner
31
31
X , pairs = build_data ()
32
- X_constrained , y = wrap_pairs (X , pairs )
33
- X_constrained , y = shuffle (X_constrained , y )
34
- (X_constrained_train , X_constrained_test , y_train ,
35
- y_test ) = train_test_split (X_constrained , y )
36
- return (X_constrained , y , X_constrained_train , X_constrained_test ,
32
+ pairs , y = wrap_pairs (X , pairs )
33
+ pairs , y = shuffle (pairs , y )
34
+ (pairs_train , pairs_test , y_train ,
35
+ y_test ) = train_test_split (pairs , y )
36
+ return (pairs , y , pairs_train , pairs_test ,
37
37
y_train , y_test )
38
38
39
39
40
40
def build_quadruplets ():
41
- # test that you can do cross validation on a ConstrainedDataset with
41
+ # test that you can do cross validation on a tuples of points with
42
42
# a WeaklySupervisedMetricLearner
43
43
X , pairs = build_data ()
44
44
c = np .column_stack (pairs )
45
- X_constrained = X [c ]
46
- X_constrained = shuffle (X_constrained )
45
+ quadruplets = X [c ]
46
+ quadruplets = shuffle (quadruplets )
47
47
y = y_train = y_test = None
48
- X_constrained_train , X_constrained_test = train_test_split (X_constrained )
49
- return (X_constrained , y , X_constrained_train , X_constrained_test ,
48
+ quadruplets_train , quadruplets_test = train_test_split (quadruplets )
49
+ return (quadruplets , y , quadruplets_train , quadruplets_test ,
50
50
y_train , y_test )
51
51
52
52
@@ -66,35 +66,35 @@ def build_quadruplets():
66
66
@pytest .mark .parametrize ('estimator, build_dataset' , list_estimators ,
67
67
ids = ids_estimators )
68
68
def test_cross_validation (estimator , build_dataset ):
69
- (X_constrained , y , X_constrained_train , X_constrained_test ,
69
+ (tuples , y , tuples_train , tuples_test ,
70
70
y_train , y_test ) = build_dataset ()
71
71
estimator = clone (estimator )
72
72
set_random_state (estimator )
73
73
74
- assert np .isfinite (cross_val_score (estimator , X_constrained , y )).all ()
74
+ assert np .isfinite (cross_val_score (estimator , tuples , y )).all ()
75
75
76
76
77
- def check_score (estimator , X_constrained , y ):
78
- score = estimator .score (X_constrained , y )
77
+ def check_score (estimator , tuples , y ):
78
+ score = estimator .score (tuples , y )
79
79
assert np .isfinite (score )
80
80
81
81
82
- def check_predict (estimator , X_constrained ):
83
- y_predicted = estimator .predict (X_constrained )
84
- assert len (y_predicted ), len (X_constrained )
82
+ def check_predict (estimator , tuples ):
83
+ y_predicted = estimator .predict (tuples )
84
+ assert len (y_predicted ), len (tuples )
85
85
86
86
87
87
@pytest .mark .parametrize ('estimator, build_dataset' , list_estimators ,
88
88
ids = ids_estimators )
89
89
def test_simple_estimator (estimator , build_dataset ):
90
- (X_constrained , y , X_constrained_train , X_constrained_test ,
90
+ (tuples , y , tuples_train , tuples_test ,
91
91
y_train , y_test ) = build_dataset ()
92
92
estimator = clone (estimator )
93
93
set_random_state (estimator )
94
94
95
- estimator .fit (X_constrained_train , y_train )
96
- check_score (estimator , X_constrained_test , y_test )
97
- check_predict (estimator , X_constrained_test )
95
+ estimator .fit (tuples_train , y_train )
96
+ check_score (estimator , tuples_test , y_test )
97
+ check_predict (estimator , tuples_test )
98
98
99
99
100
100
@pytest .mark .parametrize ('estimator' , [est [0 ] for est in list_estimators ],
@@ -122,50 +122,50 @@ def test_no_fit_attributes_set_in_init(estimator):
122
122
def test_estimators_fit_returns_self (estimator , build_dataset ):
123
123
"""Check if self is returned when calling fit"""
124
124
# From scikit-learn
125
- (X_constrained , y , X_constrained_train , X_constrained_test ,
125
+ (tuples , y , tuples_train , tuples_test ,
126
126
y_train , y_test ) = build_dataset ()
127
127
estimator = clone (estimator )
128
- assert estimator .fit (X_constrained , y ) is estimator
128
+ assert estimator .fit (tuples , y ) is estimator
129
129
130
130
131
131
@pytest .mark .parametrize ('estimator, build_dataset' , list_estimators ,
132
132
ids = ids_estimators )
133
133
def test_pipeline_consistency (estimator , build_dataset ):
134
134
# From scikit learn
135
135
# check that make_pipeline(est) gives same score as est
136
- (X_constrained , y , X_constrained_train , X_constrained_test ,
136
+ (tuples , y , tuples_train , tuples_test ,
137
137
y_train , y_test ) = build_dataset ()
138
138
estimator = clone (estimator )
139
139
pipeline = make_pipeline (estimator )
140
- estimator .fit (X_constrained , y )
141
- pipeline .fit (X_constrained , y )
140
+ estimator .fit (tuples , y )
141
+ pipeline .fit (tuples , y )
142
142
143
143
funcs = ["score" , "fit_transform" ]
144
144
145
145
for func_name in funcs :
146
146
func = getattr (estimator , func_name , None )
147
147
if func is not None :
148
148
func_pipeline = getattr (pipeline , func_name )
149
- result = func (X_constrained , y )
150
- result_pipe = func_pipeline (X_constrained , y )
149
+ result = func (tuples , y )
150
+ result_pipe = func_pipeline (tuples , y )
151
151
assert_allclose_dense_sparse (result , result_pipe )
152
152
153
153
154
154
@pytest .mark .parametrize ('estimator, build_dataset' , list_estimators ,
155
155
ids = ids_estimators )
156
156
def test_dict_unchanged (estimator , build_dataset ):
157
157
# From scikit-learn
158
- (X_constrained , y , X_constrained_train , X_constrained_test ,
158
+ (tuples , y , tuples_train , tuples_test ,
159
159
y_train , y_test ) = build_dataset ()
160
160
estimator = clone (estimator )
161
161
if hasattr (estimator , "n_components" ):
162
162
estimator .n_components = 1
163
- estimator .fit (X_constrained , y )
163
+ estimator .fit (tuples , y )
164
164
for method in ["predict" , "transform" , "decision_function" ,
165
165
"predict_proba" ]:
166
166
if hasattr (estimator , method ):
167
167
dict_before = estimator .__dict__ .copy ()
168
- getattr (estimator , method )(X_constrained )
168
+ getattr (estimator , method )(tuples )
169
169
assert estimator .__dict__ == dict_before , \
170
170
("Estimator changes __dict__ during %s"
171
171
% method )
@@ -176,14 +176,14 @@ def test_dict_unchanged(estimator, build_dataset):
176
176
def test_dont_overwrite_parameters (estimator , build_dataset ):
177
177
# From scikit-learn
178
178
# check that fit method only changes or sets private attributes
179
- (X_constrained , y , X_constrained_train , X_constrained_test ,
179
+ (tuples , y , tuples_train , tuples_test ,
180
180
y_train , y_test ) = build_dataset ()
181
181
estimator = clone (estimator )
182
182
if hasattr (estimator , "n_components" ):
183
183
estimator .n_components = 1
184
184
dict_before_fit = estimator .__dict__ .copy ()
185
185
186
- estimator .fit (X_constrained , y )
186
+ estimator .fit (tuples , y )
187
187
dict_after_fit = estimator .__dict__
188
188
189
189
public_keys_after_fit = [key for key in dict_after_fit .keys ()
0 commit comments