Skip to content

removing extra tests, as they all raise the same error of min number of classes #15069

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

Closed

Conversation

VariableVasasMT
Copy link

@VariableVasasMT VariableVasasMT commented Sep 23, 2019

Reference Issues/PRs

none

What does this implement/fix? Explain your changes.

removing extra tests, that raised the same errors

Any other comments?


This change is Reviewable

@VariableVasasMT
Copy link
Author

VariableVasasMT commented Sep 23, 2019

@raghavrv please check, i was working on machinelearnjs/machinelearnjs#243, found that these tests were written for wrong set of inputs, fixed that.

@amueller
Copy link
Member

amueller commented Sep 23, 2019

Sorry, can you please clarify what you're fixing?
@raghavrv is no longer contributing.

@VariableVasasMT
Copy link
Author

VariableVasasMT commented Oct 7, 2019

@amueller I forgot the exact change but
X = np.arange(7)
y = np.asarray([0, 1, 1, 1, 2, 2, 2])
a = StratifiedShuffleSplit(3, 0.2).split(X, y)

next(a)

we get error:

Traceback (most recent call last):
File "", line 1, in
File "/mnt/code/anaconda3/lib/python3.7/site-packages/sklearn/model_selection/_split.py", line 1315, in split
for train, test in self._iter_indices(X, y, groups):
File "/mnt/code/anaconda3/lib/python3.7/site-packages/sklearn/model_selection/_split.py", line 1695, in _iter_indices
raise ValueError("The least populated class in y has only 1"
ValueError: The least populated class in y has only 1 member, which is too few. The minimum number of groups for any class cannot be less than 2.
`

b = StratifiedShuffleSplit(3, 2).split(X, y)

next(b)

we get the same error

Traceback (most recent call last):
File "", line 1, in
File "/mnt/code/anaconda3/lib/python3.7/site-packages/sklearn/model_selection/_split.py", line 1315, in split
for train, test in self._iter_indices(X, y, groups):
File "/mnt/code/anaconda3/lib/python3.7/site-packages/sklearn/model_selection/_split.py", line 1695, in _iter_indices
raise ValueError("The least populated class in y has only 1"
ValueError: The least populated class in y has only 1 member, which is too few. The minimum number of groups for any class cannot be less than 2.

but if:
X = np.arange(9)
y = np.asarray([0, 0, 0, 1, 1, 1, 2, 2, 2])
c = StratifiedShuffleSplit(3, 2).split(X, y)
next(c)

we get error

Traceback (most recent call last):
File "", line 1, in
File "/mnt/code/anaconda3/lib/python3.7/site-packages/sklearn/model_selection/_split.py", line 1315, in split
for train, test in self._iter_indices(X, y, groups):
File "/mnt/code/anaconda3/lib/python3.7/site-packages/sklearn/model_selection/_split.py", line 1707, in _iter_indices
(n_test, n_classes))
ValueError: The test_size = 2 should be greater or equal to the number of classes = 3

which is the same error as said in comment # Check that error is raised if the test set size is smaller than n_classes

so I think that should be the order of test cases.
😄

@VariableVasasMT
Copy link
Author

@amueller please review.

@jnothman
Copy link
Member

jnothman commented Oct 22, 2019 via email

@@ -633,16 +633,17 @@ def test_stratified_shuffle_split_init():
assert_raises(ValueError, next,
StratifiedShuffleSplit(3, 0.2).split(X, y))

X = np.arange(9)
y = np.asarray([0, 0, 0, 1, 1, 1, 2, 2, 2])

# Check that error is raised if the test set size is smaller than n_classes
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jnothman the test written below wasn't testing what comment said.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of course I might be wrong in my assumption, I am not sure anymore!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid confusion in the future, we can use

msg = "The test_size = 2 should be greater or equal to the number of classes = 3"
with pytest.raises(ValueError, match=msg):
    next(StratifiedShuffleSplit(3, 2).split(X, y))

so we can check for the error message explicitly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add these to the messages!

Base automatically changed from master to main January 22, 2021 10:51
@cmarmo
Copy link
Contributor

cmarmo commented Apr 15, 2022

There is no longer assert_raises in test_split.py, which has been largely reorganized in the meanwhile.
I am closing this one.

@cmarmo cmarmo closed this Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy