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

Warn if valid data is shuffled #710

Merged
merged 1 commit into from
Oct 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions skorch/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,16 @@ def _check_kwargs(self, kwargs):
did you mean iterator_train__shuffle?

"""
# warn about usage of iterator_valid__shuffle=True, since this
# is almost certainly not what the user wants
if kwargs.get('iterator_valid__shuffle'):
warnings.warn(
"You set iterator_valid__shuffle=True; this is most likely not "
"what you want because the values returned by predict and "
"predict_proba will be shuffled.",
UserWarning)

# check for wrong arguments
unexpected_kwargs = []
missing_dunder_kwargs = []
for key in kwargs:
Expand Down
18 changes: 18 additions & 0 deletions skorch/tests/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,24 @@ def __init__(self, *args, **kwargs):
# "optimizer_2".
MyNet(module_cls, optimizer_2__lr=0.123) # should not raise

def test_net_init_with_iterator_valid_shuffle_true(
self, net_cls, module_cls, recwarn):
# If a user sets iterator_valid__shuffle=True, they might be
# in for a surprise, since predict et al. will result in
# shuffled predictions. It is best to warn about this, since
# most of the times, this is not what users actually want.
expected = (
"You set iterator_valid__shuffle=True; this is most likely not what you want "
"because the values returned by predict and predict_proba will be shuffled.")

# no warning expected here
net_cls(module_cls, iterator_valid__shuffle=False)
assert not recwarn.list

# warning expected here
with pytest.warns(UserWarning, match=expected):
net_cls(module_cls, iterator_valid__shuffle=True)

def test_fit(self, net_fit):
# fitting does not raise anything
pass
Expand Down