Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added two unit tests in test_subsample #312

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 37 additions & 0 deletions mapie/tests/test_subsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from mapie.subsample import BlockBootstrap, Subsample

random_state = 42
rng = np.random.default_rng(seed=random_state)

def test_default_parameters_SubSample() -> None:
"""Test default values of Subsample."""
Expand Down Expand Up @@ -87,3 +89,38 @@ def test_split_BlockBootstrap_error() -> None:
cv = BlockBootstrap()
with pytest.raises(ValueError, match=r".*Exactly one argument*"):
next(cv.split(X))

def test_split_samples_are_different()->None:
"""Test that subsamples are different """

X = rng.random(100)
cv = Subsample(n_resamplings=3, random_state=random_state)
trains = [x[0] for x in cv.split(X)]
tests = [x[1] for x in cv.split(X)]
with np.testing.assert_raises(AssertionError):
np.testing.assert_equal(trains[0], trains[1])
with np.testing.assert_raises(AssertionError):
np.testing.assert_equal(trains[1], trains[2])


with np.testing.assert_raises(AssertionError):
np.testing.assert_equal(tests[0], tests[1])
with np.testing.assert_raises(AssertionError):
np.testing.assert_equal(tests[1], tests[2])


def test_split_blockbootstraps_are_different()->None:
veronewra marked this conversation as resolved.
Show resolved Hide resolved
"""Test that BlockBootstrap outputs are different """
X = rng.random(100)
cv = BlockBootstrap(n_resamplings=3, length=5, random_state=random_state)
trains = [x[0] for x in cv.split(X)]
tests = [x[1] for x in cv.split(X)]
with np.testing.assert_raises(AssertionError):
np.testing.assert_equal(trains[0], trains[1])
with np.testing.assert_raises(AssertionError):
np.testing.assert_equal(trains[1], trains[2])

with np.testing.assert_raises(AssertionError):
np.testing.assert_equal(tests[0], tests[1])
with np.testing.assert_raises(AssertionError):
np.testing.assert_equal(tests[1], tests[2])