Skip to content

Commit 2fa047d

Browse files
committed
ENH: rename groups into partition in tests
1 parent d6aa546 commit 2fa047d

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

mapie/tests/test_mondrian.py

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def test_valid_estimators_dont_fail(mapie_estimator_name):
186186
x, y = TOY_DATASETS[task]
187187
y = np.abs(y) # to avoid negative values with Gamma NCS
188188
ml_model = ML_MODELS[task]
189-
groups = np.random.choice(10, len(x))
189+
partition = np.random.choice(10, len(x))
190190
model = clone(ml_model)
191191
model.fit(x, y)
192192
mapie_inst = deepcopy(mapie_estimator)
@@ -195,8 +195,8 @@ def test_valid_estimators_dont_fail(mapie_estimator_name):
195195
estimator=model, cv="prefit", **mapie_kwargs
196196
)
197197
)
198-
mondrian_cp.fit(x, y, groups=groups)
199-
mondrian_cp.predict(x, groups=groups, alpha=.2)
198+
mondrian_cp.fit(x, y, partition=partition)
199+
mondrian_cp.predict(x, partition=partition, alpha=.2)
200200

201201

202202
@pytest.mark.parametrize(
@@ -210,7 +210,7 @@ def test_non_cs_fails(mapie_estimator_name):
210210
task = task_dict["task"]
211211
x, y = TOY_DATASETS[task]
212212
ml_model = ML_MODELS[task]
213-
groups = np.random.choice(10, len(x))
213+
partition = np.random.choice(10, len(x))
214214
model = clone(ml_model)
215215
model.fit(x, y)
216216
mapie_inst = deepcopy(mapie_estimator)
@@ -220,7 +220,7 @@ def test_non_cs_fails(mapie_estimator_name):
220220
)
221221
)
222222
with pytest.raises(ValueError, match=r".*The conformity score for*"):
223-
mondrian_cp.fit(x, y, groups=groups)
223+
mondrian_cp.fit(x, y, partition=partition)
224224

225225

226226
@pytest.mark.parametrize("mapie_estimator_name", VALID_MAPIE_ESTIMATORS_NAMES)
@@ -233,7 +233,7 @@ def test_invalid_cv_fails(mapie_estimator_name, non_valid_cv):
233233
task = task_dict["task"]
234234
x, y = TOY_DATASETS[task]
235235
ml_model = ML_MODELS[task]
236-
groups = np.random.choice(10, len(x))
236+
partition = np.random.choice(10, len(x))
237237
model = clone(ml_model)
238238
mapie_inst = deepcopy(mapie_estimator)
239239
mondrian_cp = MondrianCP(
@@ -242,7 +242,7 @@ def test_invalid_cv_fails(mapie_estimator_name, non_valid_cv):
242242
)
243243
)
244244
with pytest.raises(ValueError, match=r".*estimator uses cv='prefit'*"):
245-
mondrian_cp.fit(x, y, groups=groups)
245+
mondrian_cp.fit(x, y, partition=partition)
246246

247247

248248
@pytest.mark.parametrize(
@@ -257,7 +257,7 @@ def test_non_valid_estimators_fails(mapie_estimator_name):
257257
x, y = TOY_DATASETS[task]
258258
y = np.abs(y) # to avoid negative values with Gamma NCS
259259
ml_model = ML_MODELS[task]
260-
groups = np.random.choice(10, len(x))
260+
partition = np.random.choice(10, len(x))
261261
model = clone(ml_model)
262262
model.fit(x, y)
263263
mapie_inst = deepcopy(mapie_estimator)
@@ -277,89 +277,89 @@ def test_non_valid_estimators_fails(mapie_estimator_name):
277277
)
278278
with pytest.raises(ValueError, match=r".*The estimator must be a*"):
279279
if task == "multilabel_classification":
280-
mondrian_cp.fit(x, y, groups=groups)
280+
mondrian_cp.fit(x, y, partition=partition)
281281
elif task == "calibration":
282-
mondrian_cp.fit(x, y, groups=groups, **mapie_kwargs)
282+
mondrian_cp.fit(x, y, partition=partition, **mapie_kwargs)
283283
else:
284-
mondrian_cp.fit(x, y, groups=groups, **mapie_kwargs)
284+
mondrian_cp.fit(x, y, partition=partition, **mapie_kwargs)
285285

286286

287-
def test_groups_not_defined_by_integers_fails():
288-
"""Test that groups not defined by integers fails"""
287+
def test_partition_not_defined_by_integers_fails():
288+
"""Test that partition not defined by integers fails"""
289289
x, y = TOY_DATASETS["classification"]
290290
ml_model = ML_MODELS["classification"]
291291
model = clone(ml_model)
292292
model.fit(x, y)
293293
mondrian = MondrianCP(
294294
mapie_estimator=MapieClassifier(estimator=model, cv="prefit")
295295
)
296-
groups = np.random.choice(10, len(x)).astype(str)
296+
partition = np.random.choice(10, len(x)).astype(str)
297297
with pytest.raises(
298-
ValueError, match=r".*The groups must be defined by integers*"
298+
ValueError, match=r".*The partition must be defined by integers*"
299299
):
300-
mondrian.fit(x, y, groups=groups)
300+
mondrian.fit(x, y, partition=partition)
301301

302302

303-
def test_groups_with_less_than_2_fails():
304-
"""Test that groups with less than 2 elements fails"""
303+
def test_partition_with_less_than_2_fails():
304+
"""Test that partition with less than 2 elements fails"""
305305
x, y = TOY_DATASETS["classification"]
306306
ml_model = ML_MODELS["classification"]
307307
model = clone(ml_model)
308308
model.fit(x, y)
309309
mondrian = MondrianCP(
310310
mapie_estimator=MapieClassifier(estimator=model, cv="prefit")
311311
)
312-
groups = np.array([1] + [2] * (len(x) - 1))
312+
partition = np.array([1] + [2] * (len(x) - 1))
313313
with pytest.raises(
314314
ValueError, match=r".*There must be at least 2 individuals*"
315315
):
316-
mondrian.fit(x, y, groups=groups)
316+
mondrian.fit(x, y, partition=partition)
317317

318318

319-
def test_groups_and_x_have_same_length_in_fit():
320-
"""Test that groups and x have the same length in fit"""
319+
def test_partition_and_x_have_same_length_in_fit():
320+
"""Test that partition and x have the same length in fit"""
321321
x, y = TOY_DATASETS["classification"]
322322
ml_model = ML_MODELS["classification"]
323323
model = clone(ml_model)
324324
model.fit(x, y)
325325
mondrian = MondrianCP(
326326
mapie_estimator=MapieClassifier(estimator=model, cv="prefit")
327327
)
328-
groups = np.random.choice(10, len(x) - 1)
328+
partition = np.random.choice(10, len(x) - 1)
329329
with pytest.raises(ValueError, match=r".*he number of individuals in*"):
330-
mondrian.fit(x, y, groups=groups)
330+
mondrian.fit(x, y, partition=partition)
331331

332332

333-
def test_all_groups_in_predict_are_in_fit():
334-
"""Test that all groups in predict are in fit"""
333+
def test_all_partition_in_predict_are_in_fit():
334+
"""Test that all partition in predict are in fit"""
335335
x, y = TOY_DATASETS["classification"]
336336
ml_model = ML_MODELS["classification"]
337337
model = clone(ml_model)
338338
model.fit(x, y)
339339
mondrian = MondrianCP(
340340
mapie_estimator=MapieClassifier(estimator=model, cv="prefit")
341341
)
342-
groups = np.random.choice(10, len(x))
343-
mondrian.fit(x, y, groups=groups)
344-
groups = np.array([99] * len(x))
342+
partition = np.random.choice(10, len(x))
343+
mondrian.fit(x, y, partition=partition)
344+
partition = np.array([99] * len(x))
345345
with pytest.raises(ValueError, match=r".*There is at least one new*"):
346-
mondrian.predict(x, groups=groups, alpha=.2)
346+
mondrian.predict(x, partition=partition, alpha=.2)
347347

348348

349-
def test_groups_and_x_have_same_length_in_predict():
350-
"""Test that groups and x have the same length in predict"""
349+
def test_partition_and_x_have_same_length_in_predict():
350+
"""Test that partition and x have the same length in predict"""
351351
x, y = TOY_DATASETS["classification"]
352352
ml_model = ML_MODELS["classification"]
353353
model = clone(ml_model)
354354
model.fit(x, y)
355355
mondrian = MondrianCP(
356356
mapie_estimator=MapieClassifier(estimator=model, cv="prefit")
357357
)
358-
groups = np.random.choice(10, len(x))
359-
mondrian.fit(x, y, groups=groups)
360-
groups = np.random.choice(10, len(x) - 1)
358+
partition = np.random.choice(10, len(x))
359+
mondrian.fit(x, y, partition=partition)
360+
partition = np.random.choice(10, len(x) - 1)
361361
with pytest.raises(ValueError, match=r".*The number of individuals in*"):
362-
mondrian.predict(x, groups=groups, alpha=.2)
362+
mondrian.predict(x, partition=partition, alpha=.2)
363363

364364

365365
def test_alpha_none_return_one_element():
@@ -371,24 +371,24 @@ def test_alpha_none_return_one_element():
371371
mondrian = MondrianCP(
372372
mapie_estimator=MapieClassifier(estimator=model, cv="prefit")
373373
)
374-
groups = np.random.choice(10, len(x))
375-
mondrian.fit(x, y, groups=groups)
376-
preds = mondrian.predict(x, groups=groups)
374+
partition = np.random.choice(10, len(x))
375+
mondrian.fit(x, y, partition=partition)
376+
preds = mondrian.predict(x, partition=partition)
377377
assert len(preds) == len(x)
378378

379379

380-
def test_groups_is_list_ok():
381-
"""Test that the groups can be a list"""
380+
def test_partition_is_list_ok():
381+
"""Test that the partition can be a list"""
382382
x, y = TOY_DATASETS["classification"]
383383
ml_model = ML_MODELS["classification"]
384384
model = clone(ml_model)
385385
model.fit(x, y)
386386
mondrian = MondrianCP(
387387
mapie_estimator=MapieClassifier(estimator=model, cv="prefit")
388388
)
389-
groups = np.random.choice(10, len(x)).tolist()
390-
mondrian.fit(x, y, groups=groups)
391-
mondrian.predict(x, groups=groups, alpha=.2)
389+
partition = np.random.choice(10, len(x)).tolist()
390+
mondrian.fit(x, y, partition=partition)
391+
mondrian.predict(x, partition=partition, alpha=.2)
392392

393393

394394
@pytest.mark.parametrize("mapie_estimator_name", VALID_MAPIE_ESTIMATORS_NAMES)
@@ -402,7 +402,7 @@ def test_same_results_if_only_one_group(mapie_estimator_name, alpha):
402402
x, y = TOY_DATASETS[task]
403403
y = np.abs(y)
404404
ml_model = ML_MODELS[task]
405-
groups = [0] * len(x)
405+
partition = [0] * len(x)
406406
model = clone(ml_model)
407407
model.fit(x, y)
408408
mapie_inst_mondrian = deepcopy(mapie_estimator)
@@ -415,9 +415,9 @@ def test_same_results_if_only_one_group(mapie_estimator_name, alpha):
415415
mapie_classic = mapie_classic_inst(
416416
estimator=model, cv="prefit", random_state=0, **mapie_kwargs,
417417
)
418-
mondrian_cp.fit(x, y, groups=groups)
418+
mondrian_cp.fit(x, y, partition=partition)
419419
mapie_classic.fit(x, y)
420-
mondrian_pred = mondrian_cp.predict(x, groups=groups, alpha=alpha)
420+
mondrian_pred = mondrian_cp.predict(x, partition=partition, alpha=alpha)
421421
classic_pred = mapie_classic.predict(x, alpha=alpha)
422422
assert np.allclose(mondrian_pred[0], classic_pred[0])
423423
assert np.allclose(mondrian_pred[1], classic_pred[1])

0 commit comments

Comments
 (0)